blob: 938ef1cb68ccce56634a5873f706805bdc09a924 [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;
Alex Deucher97b2e202015-04-20 16:51:00 -040098
Chunming Zhou4b559c92015-07-21 15:53:04 +080099#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -0400100#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
101#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
102/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
103#define AMDGPU_IB_POOL_SIZE 16
104#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
105#define AMDGPUFB_CONN_LIMIT 4
106#define AMDGPU_BIOS_NUM_SCRATCH 8
107
Alex Deucher97b2e202015-04-20 16:51:00 -0400108/* max number of rings */
109#define AMDGPU_MAX_RINGS 16
110#define AMDGPU_MAX_GFX_RINGS 1
111#define AMDGPU_MAX_COMPUTE_RINGS 8
Alex Deucher6f0359f2016-08-24 17:15:33 -0400112#define AMDGPU_MAX_VCE_RINGS 3
Alex Deucher97b2e202015-04-20 16:51:00 -0400113
Jammy Zhou36f523a2015-09-01 12:54:27 +0800114/* max number of IP instances */
115#define AMDGPU_MAX_SDMA_INSTANCES 2
116
Alex Deucher97b2e202015-04-20 16:51:00 -0400117/* hardcode that limit for now */
118#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
119
120/* hard reset data */
121#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
122
123/* reset flags */
124#define AMDGPU_RESET_GFX (1 << 0)
125#define AMDGPU_RESET_COMPUTE (1 << 1)
126#define AMDGPU_RESET_DMA (1 << 2)
127#define AMDGPU_RESET_CP (1 << 3)
128#define AMDGPU_RESET_GRBM (1 << 4)
129#define AMDGPU_RESET_DMA1 (1 << 5)
130#define AMDGPU_RESET_RLC (1 << 6)
131#define AMDGPU_RESET_SEM (1 << 7)
132#define AMDGPU_RESET_IH (1 << 8)
133#define AMDGPU_RESET_VMC (1 << 9)
134#define AMDGPU_RESET_MC (1 << 10)
135#define AMDGPU_RESET_DISPLAY (1 << 11)
136#define AMDGPU_RESET_UVD (1 << 12)
137#define AMDGPU_RESET_VCE (1 << 13)
138#define AMDGPU_RESET_VCE1 (1 << 14)
139
Alex Deucher97b2e202015-04-20 16:51:00 -0400140/* GFX current status */
141#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
142#define AMDGPU_GFX_SAFE_MODE 0x00000001L
143#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
144#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
145#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
146
147/* max cursor sizes (in pixels) */
148#define CIK_CURSOR_WIDTH 128
149#define CIK_CURSOR_HEIGHT 128
150
151struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400152struct amdgpu_ib;
153struct amdgpu_vm;
154struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400155struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800156struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400157struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400158struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400159
160enum amdgpu_cp_irq {
161 AMDGPU_CP_IRQ_GFX_EOP = 0,
162 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
163 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
164 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
165 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
166 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
167 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
168 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
169 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
170
171 AMDGPU_CP_IRQ_LAST
172};
173
174enum amdgpu_sdma_irq {
175 AMDGPU_SDMA_IRQ_TRAP0 = 0,
176 AMDGPU_SDMA_IRQ_TRAP1,
177
178 AMDGPU_SDMA_IRQ_LAST
179};
180
181enum amdgpu_thermal_irq {
182 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
183 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
184
185 AMDGPU_THERMAL_IRQ_LAST
186};
187
Alex Deucher97b2e202015-04-20 16:51:00 -0400188int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400189 enum amd_ip_block_type block_type,
190 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400191int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400192 enum amd_ip_block_type block_type,
193 enum amd_powergating_state state);
Alex Deucher5dbbb602016-06-23 11:41:04 -0400194int amdgpu_wait_for_idle(struct amdgpu_device *adev,
195 enum amd_ip_block_type block_type);
196bool amdgpu_is_idle(struct amdgpu_device *adev,
197 enum amd_ip_block_type block_type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400198
199struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400200 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400201 u32 major;
202 u32 minor;
203 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400204 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400205};
206
207int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400208 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400209 u32 major, u32 minor);
210
211const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
212 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400213 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400214
215/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
216struct amdgpu_buffer_funcs {
217 /* maximum bytes in a single operation */
218 uint32_t copy_max_bytes;
219
220 /* number of dw to reserve per operation */
221 unsigned copy_num_dw;
222
223 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800224 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400225 /* src addr in bytes */
226 uint64_t src_offset,
227 /* dst addr in bytes */
228 uint64_t dst_offset,
229 /* number of byte to transfer */
230 uint32_t byte_count);
231
232 /* maximum bytes in a single operation */
233 uint32_t fill_max_bytes;
234
235 /* number of dw to reserve per operation */
236 unsigned fill_num_dw;
237
238 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800239 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400240 /* value to write to memory */
241 uint32_t src_data,
242 /* dst addr in bytes */
243 uint64_t dst_offset,
244 /* number of byte to fill */
245 uint32_t byte_count);
246};
247
248/* provided by hw blocks that can write ptes, e.g., sdma */
249struct amdgpu_vm_pte_funcs {
250 /* copy pte entries from GART */
251 void (*copy_pte)(struct amdgpu_ib *ib,
252 uint64_t pe, uint64_t src,
253 unsigned count);
254 /* write pte one entry at a time with addr mapping */
Christian Königde9ea7b2016-08-12 11:33:30 +0200255 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
256 uint64_t value, unsigned count,
257 uint32_t incr);
Alex Deucher97b2e202015-04-20 16:51:00 -0400258 /* for linear pte/pde updates without addr mapping */
259 void (*set_pte_pde)(struct amdgpu_ib *ib,
260 uint64_t pe,
261 uint64_t addr, unsigned count,
262 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400263};
264
265/* provided by the gmc block */
266struct amdgpu_gart_funcs {
267 /* flush the vm tlb via mmio */
268 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
269 uint32_t vmid);
270 /* write pte/pde updates using the cpu */
271 int (*set_pte_pde)(struct amdgpu_device *adev,
272 void *cpu_pt_addr, /* cpu addr of page table */
273 uint32_t gpu_page_idx, /* pte/pde to update */
274 uint64_t addr, /* addr to write into pte/pde */
275 uint32_t flags); /* access flags */
276};
277
278/* provided by the ih block */
279struct amdgpu_ih_funcs {
280 /* ring read/write ptr handling, called from interrupt context */
281 u32 (*get_wptr)(struct amdgpu_device *adev);
282 void (*decode_iv)(struct amdgpu_device *adev,
283 struct amdgpu_iv_entry *entry);
284 void (*set_rptr)(struct amdgpu_device *adev);
285};
286
287/* provided by hw blocks that expose a ring buffer for commands */
288struct amdgpu_ring_funcs {
289 /* ring read/write ptr handling */
290 u32 (*get_rptr)(struct amdgpu_ring *ring);
291 u32 (*get_wptr)(struct amdgpu_ring *ring);
292 void (*set_wptr)(struct amdgpu_ring *ring);
293 /* validating and patching of IBs */
294 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
295 /* command emit functions */
296 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200297 struct amdgpu_ib *ib,
298 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400299 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800300 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100301 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400302 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
303 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200304 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800305 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400306 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
307 uint32_t gds_base, uint32_t gds_size,
308 uint32_t gws_base, uint32_t gws_size,
309 uint32_t oa_base, uint32_t oa_size);
310 /* testing functions */
311 int (*test_ring)(struct amdgpu_ring *ring);
Christian Königbbec97a2016-07-05 21:07:17 +0200312 int (*test_ib)(struct amdgpu_ring *ring, long timeout);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800313 /* insert NOP packets */
314 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100315 /* pad the indirect buffer to the necessary number of dw */
316 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800317 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
318 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Christian Königf06505b2016-07-20 13:49:34 +0200319 /* note usage for clock and power gating */
320 void (*begin_use)(struct amdgpu_ring *ring);
321 void (*end_use)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400322};
323
324/*
325 * BIOS.
326 */
327bool amdgpu_get_bios(struct amdgpu_device *adev);
328bool amdgpu_read_bios(struct amdgpu_device *adev);
329
330/*
331 * Dummy page
332 */
333struct amdgpu_dummy_page {
334 struct page *page;
335 dma_addr_t addr;
336};
337int amdgpu_dummy_page_init(struct amdgpu_device *adev);
338void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
339
340
341/*
342 * Clocks
343 */
344
345#define AMDGPU_MAX_PPLL 3
346
347struct amdgpu_clock {
348 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
349 struct amdgpu_pll spll;
350 struct amdgpu_pll mpll;
351 /* 10 Khz units */
352 uint32_t default_mclk;
353 uint32_t default_sclk;
354 uint32_t default_dispclk;
355 uint32_t current_dispclk;
356 uint32_t dp_extclk;
357 uint32_t max_pixel_clock;
358};
359
360/*
361 * Fences.
362 */
363struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400364 uint64_t gpu_addr;
365 volatile uint32_t *cpu_addr;
366 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100367 uint32_t sync_seq;
368 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400369 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400370 struct amdgpu_irq_src *irq_src;
371 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100372 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100373 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100374 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100375 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400376};
377
378/* some special values for the owner field */
379#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
380#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400381
Chunming Zhou890ee232015-06-01 14:35:03 +0800382#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
383#define AMDGPU_FENCE_FLAG_INT (1 << 1)
384
Alex Deucher97b2e202015-04-20 16:51:00 -0400385int amdgpu_fence_driver_init(struct amdgpu_device *adev);
386void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
387void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
388
Christian Könige6151a02016-03-15 14:52:26 +0100389int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
390 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400391int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
392 struct amdgpu_irq_src *irq_src,
393 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400394void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
395void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100396int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400397void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400398int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
399unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
400
Alex Deucher97b2e202015-04-20 16:51:00 -0400401/*
Flora Cuic632d792016-08-02 11:32:41 +0800402 * BO.
Alex Deucher97b2e202015-04-20 16:51:00 -0400403 */
Christian König29b32592016-04-15 17:19:16 +0200404
Alex Deucher97b2e202015-04-20 16:51:00 -0400405struct amdgpu_bo_list_entry {
406 struct amdgpu_bo *robj;
407 struct ttm_validate_buffer tv;
408 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400409 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100410 struct page **user_pages;
411 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400412};
413
414struct amdgpu_bo_va_mapping {
415 struct list_head list;
416 struct interval_tree_node it;
417 uint64_t offset;
418 uint32_t flags;
419};
420
421/* bo virtual addresses in a specific vm */
422struct amdgpu_bo_va {
423 /* protected by bo being reserved */
424 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800425 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400426 unsigned ref_count;
427
Christian König7fc11952015-07-30 11:53:42 +0200428 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400429 struct list_head vm_status;
430
Christian König7fc11952015-07-30 11:53:42 +0200431 /* mappings for this bo_va */
432 struct list_head invalids;
433 struct list_head valids;
434
Alex Deucher97b2e202015-04-20 16:51:00 -0400435 /* constant after initialization */
436 struct amdgpu_vm *vm;
437 struct amdgpu_bo *bo;
438};
439
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800440#define AMDGPU_GEM_DOMAIN_MAX 0x3
441
Alex Deucher97b2e202015-04-20 16:51:00 -0400442struct amdgpu_bo {
443 /* Protected by gem.mutex */
444 struct list_head list;
445 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100446 u32 prefered_domains;
447 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800448 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400449 struct ttm_placement placement;
450 struct ttm_buffer_object tbo;
451 struct ttm_bo_kmap_obj kmap;
452 u64 flags;
453 unsigned pin_count;
454 void *kptr;
455 u64 tiling_flags;
456 u64 metadata_flags;
457 void *metadata;
458 u32 metadata_size;
459 /* list of all virtual address to which this bo
460 * is associated to
461 */
462 struct list_head va;
463 /* Constant after initialization */
464 struct amdgpu_device *adev;
465 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100466 struct amdgpu_bo *parent;
Chunming Zhoue7893c42016-07-26 14:13:21 +0800467 struct amdgpu_bo *shadow;
Alex Deucher97b2e202015-04-20 16:51:00 -0400468
469 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400470 struct amdgpu_mn *mn;
471 struct list_head mn_list;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +0800472 struct list_head shadow_list;
Alex Deucher97b2e202015-04-20 16:51:00 -0400473};
474#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
475
476void amdgpu_gem_object_free(struct drm_gem_object *obj);
477int amdgpu_gem_object_open(struct drm_gem_object *obj,
478 struct drm_file *file_priv);
479void amdgpu_gem_object_close(struct drm_gem_object *obj,
480 struct drm_file *file_priv);
481unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
482struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200483struct drm_gem_object *
484amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
485 struct dma_buf_attachment *attach,
486 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400487struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
488 struct drm_gem_object *gobj,
489 int flags);
490int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
491void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
492struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
493void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
494void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
495int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
496
497/* sub-allocation manager, it has to be protected by another lock.
498 * By conception this is an helper for other part of the driver
499 * like the indirect buffer or semaphore, which both have their
500 * locking.
501 *
502 * Principe is simple, we keep a list of sub allocation in offset
503 * order (first entry has offset == 0, last entry has the highest
504 * offset).
505 *
506 * When allocating new object we first check if there is room at
507 * the end total_size - (last_object_offset + last_object_size) >=
508 * alloc_size. If so we allocate new object there.
509 *
510 * When there is not enough room at the end, we start waiting for
511 * each sub object until we reach object_offset+object_size >=
512 * alloc_size, this object then become the sub object we return.
513 *
514 * Alignment can't be bigger than page size.
515 *
516 * Hole are not considered for allocation to keep things simple.
517 * Assumption is that there won't be hole (all object on same
518 * alignment).
519 */
Christian König6ba60b82016-03-11 14:50:08 +0100520
521#define AMDGPU_SA_NUM_FENCE_LISTS 32
522
Alex Deucher97b2e202015-04-20 16:51:00 -0400523struct amdgpu_sa_manager {
524 wait_queue_head_t wq;
525 struct amdgpu_bo *bo;
526 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100527 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400528 struct list_head olist;
529 unsigned size;
530 uint64_t gpu_addr;
531 void *cpu_ptr;
532 uint32_t domain;
533 uint32_t align;
534};
535
Alex Deucher97b2e202015-04-20 16:51:00 -0400536/* sub-allocation buffer */
537struct amdgpu_sa_bo {
538 struct list_head olist;
539 struct list_head flist;
540 struct amdgpu_sa_manager *manager;
541 unsigned soffset;
542 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800543 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400544};
545
546/*
547 * GEM objects.
548 */
Christian König418aa0c2016-02-15 16:59:57 +0100549void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400550int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
551 int alignment, u32 initial_domain,
552 u64 flags, bool kernel,
553 struct drm_gem_object **obj);
554
555int amdgpu_mode_dumb_create(struct drm_file *file_priv,
556 struct drm_device *dev,
557 struct drm_mode_create_dumb *args);
558int amdgpu_mode_dumb_mmap(struct drm_file *filp,
559 struct drm_device *dev,
560 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400561/*
562 * Synchronization
563 */
564struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800565 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800566 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400567};
568
569void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200570int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
571 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400572int amdgpu_sync_resv(struct amdgpu_device *adev,
573 struct amdgpu_sync *sync,
574 struct reservation_object *resv,
575 void *owner);
Christian König1fbb2e92016-06-01 10:47:36 +0200576struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
577 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200578struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100579void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100580int amdgpu_sync_init(void);
581void amdgpu_sync_fini(void);
Rex Zhud573de22016-05-12 13:27:28 +0800582int amdgpu_fence_slab_init(void);
583void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400584
585/*
586 * GART structures, functions & helpers
587 */
588struct amdgpu_mc;
589
590#define AMDGPU_GPU_PAGE_SIZE 4096
591#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
592#define AMDGPU_GPU_PAGE_SHIFT 12
593#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
594
595struct amdgpu_gart {
596 dma_addr_t table_addr;
597 struct amdgpu_bo *robj;
598 void *ptr;
599 unsigned num_gpu_pages;
600 unsigned num_cpu_pages;
601 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200602#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400603 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200604#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400605 bool ready;
606 const struct amdgpu_gart_funcs *gart_funcs;
607};
608
609int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
610void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
611int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
612void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
613int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
614void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
615int amdgpu_gart_init(struct amdgpu_device *adev);
616void amdgpu_gart_fini(struct amdgpu_device *adev);
617void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
618 int pages);
619int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
620 int pages, struct page **pagelist,
621 dma_addr_t *dma_addr, uint32_t flags);
622
623/*
624 * GPU MC structures, functions & helpers
625 */
626struct amdgpu_mc {
627 resource_size_t aper_size;
628 resource_size_t aper_base;
629 resource_size_t agp_base;
630 /* for some chips with <= 32MB we need to lie
631 * about vram size near mc fb location */
632 u64 mc_vram_size;
633 u64 visible_vram_size;
634 u64 gtt_size;
635 u64 gtt_start;
636 u64 gtt_end;
637 u64 vram_start;
638 u64 vram_end;
639 unsigned vram_width;
640 u64 real_vram_size;
641 int vram_mtrr;
642 u64 gtt_base_align;
643 u64 mc_mask;
644 const struct firmware *fw; /* MC firmware */
645 uint32_t fw_version;
646 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800647 uint32_t vram_type;
Chunming Zhou50b01972016-07-18 16:59:24 +0800648 uint32_t srbm_soft_reset;
649 struct amdgpu_mode_mc_save save;
Alex Deucher97b2e202015-04-20 16:51:00 -0400650};
651
652/*
653 * GPU doorbell structures, functions & helpers
654 */
655typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
656{
657 AMDGPU_DOORBELL_KIQ = 0x000,
658 AMDGPU_DOORBELL_HIQ = 0x001,
659 AMDGPU_DOORBELL_DIQ = 0x002,
660 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
661 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
662 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
663 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
664 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
665 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
666 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
667 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
668 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
669 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
670 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
671 AMDGPU_DOORBELL_IH = 0x1E8,
672 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
673 AMDGPU_DOORBELL_INVALID = 0xFFFF
674} AMDGPU_DOORBELL_ASSIGNMENT;
675
676struct amdgpu_doorbell {
677 /* doorbell mmio */
678 resource_size_t base;
679 resource_size_t size;
680 u32 __iomem *ptr;
681 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
682};
683
684void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
685 phys_addr_t *aperture_base,
686 size_t *aperture_size,
687 size_t *start_offset);
688
689/*
690 * IRQS.
691 */
692
693struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900694 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400695 struct work_struct unpin_work;
696 struct amdgpu_device *adev;
697 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900698 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400699 uint64_t base;
700 struct drm_pending_vblank_event *event;
701 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200702 struct fence *excl;
703 unsigned shared_count;
704 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100705 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400706 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400707};
708
709
710/*
711 * CP & rings.
712 */
713
714struct amdgpu_ib {
715 struct amdgpu_sa_bo *sa_bo;
716 uint32_t length_dw;
717 uint64_t gpu_addr;
718 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800719 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400720};
721
722enum amdgpu_ring_type {
723 AMDGPU_RING_TYPE_GFX,
724 AMDGPU_RING_TYPE_COMPUTE,
725 AMDGPU_RING_TYPE_SDMA,
726 AMDGPU_RING_TYPE_UVD,
727 AMDGPU_RING_TYPE_VCE
728};
729
Nils Wallménius62250a92016-04-10 16:30:00 +0200730extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800731
Christian König50838c82016-02-03 13:44:52 +0100732int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800733 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100734int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
735 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800736
Christian Königa5fb4ec2016-06-29 15:10:31 +0200737void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100738void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100739int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100740 struct amd_sched_entity *entity, void *owner,
741 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800742
Alex Deucher97b2e202015-04-20 16:51:00 -0400743struct amdgpu_ring {
744 struct amdgpu_device *adev;
745 const struct amdgpu_ring_funcs *funcs;
746 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200747 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400748
Alex Deucher97b2e202015-04-20 16:51:00 -0400749 struct amdgpu_bo *ring_obj;
750 volatile uint32_t *ring;
751 unsigned rptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400752 unsigned wptr;
753 unsigned wptr_old;
754 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100755 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400756 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400757 uint64_t gpu_addr;
758 uint32_t align_mask;
759 uint32_t ptr_mask;
760 bool ready;
761 u32 nop;
762 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400763 u32 me;
764 u32 pipe;
765 u32 queue;
766 struct amdgpu_bo *mqd_obj;
767 u32 doorbell_index;
768 bool use_doorbell;
769 unsigned wptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400770 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200771 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400772 enum amdgpu_ring_type type;
773 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800774 unsigned cond_exe_offs;
Christian König92c023c2016-07-19 14:34:17 +0200775 u64 cond_exe_gpu_addr;
776 volatile u32 *cond_exe_cpu_addr;
Monk Liua909c6b2016-06-14 12:02:21 -0400777#if defined(CONFIG_DEBUG_FS)
778 struct dentry *ent;
779#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400780};
781
782/*
783 * VM
784 */
785
786/* maximum number of VMIDs */
787#define AMDGPU_NUM_VM 16
788
Christian König96105e52016-08-12 12:59:59 +0200789/* Maximum number of PTEs the hardware can write with one command */
790#define AMDGPU_VM_MAX_UPDATE_SIZE 0x3FFFF
791
Alex Deucher97b2e202015-04-20 16:51:00 -0400792/* number of entries in page table */
793#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
794
795/* PTBs (Page Table Blocks) need to be aligned to 32K */
796#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
Alex Deucher97b2e202015-04-20 16:51:00 -0400797
Christian König1303c732016-08-03 17:46:42 +0200798/* LOG2 number of continuous pages for the fragment field */
799#define AMDGPU_LOG2_PAGES_PER_FRAG 4
800
Alex Deucher97b2e202015-04-20 16:51:00 -0400801#define AMDGPU_PTE_VALID (1 << 0)
802#define AMDGPU_PTE_SYSTEM (1 << 1)
803#define AMDGPU_PTE_SNOOPED (1 << 2)
804
805/* VI only */
806#define AMDGPU_PTE_EXECUTABLE (1 << 4)
807
808#define AMDGPU_PTE_READABLE (1 << 5)
809#define AMDGPU_PTE_WRITEABLE (1 << 6)
810
Christian König1303c732016-08-03 17:46:42 +0200811#define AMDGPU_PTE_FRAG(x) ((x & 0x1f) << 7)
Alex Deucher97b2e202015-04-20 16:51:00 -0400812
Christian Königd9c13152015-09-28 12:31:26 +0200813/* How to programm VM fault handling */
814#define AMDGPU_VM_FAULT_STOP_NEVER 0
815#define AMDGPU_VM_FAULT_STOP_FIRST 1
816#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
817
Alex Deucher97b2e202015-04-20 16:51:00 -0400818struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100819 struct amdgpu_bo_list_entry entry;
820 uint64_t addr;
Chunming Zhou6557e3d2016-08-15 11:36:54 +0800821 uint64_t shadow_addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400822};
823
Alex Deucher97b2e202015-04-20 16:51:00 -0400824struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100825 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400826 struct rb_root va;
827
Christian König7fc11952015-07-30 11:53:42 +0200828 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400829 spinlock_t status_lock;
830
831 /* BOs moved, but not yet updated in the PT */
832 struct list_head invalidated;
833
Christian König7fc11952015-07-30 11:53:42 +0200834 /* BOs cleared in the PT because of a move */
835 struct list_head cleared;
836
837 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400838 struct list_head freed;
839
840 /* contains the page directory */
841 struct amdgpu_bo *page_directory;
842 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200843 struct fence *page_directory_fence;
Christian König5a712a82016-06-21 16:28:15 +0200844 uint64_t last_eviction_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400845
846 /* array of page tables, one for each page directory entry */
847 struct amdgpu_vm_pt *page_tables;
848
849 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100850 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100851
jimqu81d75a32015-12-04 17:17:00 +0800852 /* protecting freed */
853 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100854
855 /* Scheduler entity for page table updates */
856 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800857
858 /* client id */
859 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400860};
861
Christian Königbcb1ba32016-03-08 15:40:11 +0100862struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100863 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100864 struct fence *first;
865 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100866 struct fence *last_flush;
Christian König0ea54b92016-05-04 10:20:01 +0200867 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100868
Christian Königbcb1ba32016-03-08 15:40:11 +0100869 uint64_t pd_gpu_addr;
870 /* last flushed PD/PT update */
871 struct fence *flushed_updates;
872
Chunming Zhou6adb0512016-06-27 17:06:01 +0800873 uint32_t current_gpu_reset_count;
874
Christian König971fe9a92016-03-01 15:09:25 +0100875 uint32_t gds_base;
876 uint32_t gds_size;
877 uint32_t gws_base;
878 uint32_t gws_size;
879 uint32_t oa_base;
880 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100881};
Christian König8d0a7ce2015-11-03 20:58:50 +0100882
Christian Königa9a78b32016-01-21 10:19:11 +0100883struct amdgpu_vm_manager {
884 /* Handling of VMIDs */
885 struct mutex lock;
886 unsigned num_ids;
887 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100888 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100889
Christian König1fbb2e92016-06-01 10:47:36 +0200890 /* Handling of VM fences */
891 u64 fence_context;
892 unsigned seqno[AMDGPU_MAX_RINGS];
893
Christian König8b4fb002015-11-15 16:04:16 +0100894 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400895 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100896 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400897 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100898 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400899 /* vm pte handling */
900 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100901 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
902 unsigned vm_pte_num_rings;
903 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800904 /* client id counter */
905 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400906};
907
Christian Königa9a78b32016-01-21 10:19:11 +0100908void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100909void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100910int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
911void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100912void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
913 struct list_head *validated,
914 struct amdgpu_bo_list_entry *entry);
Christian König5a712a82016-06-21 16:28:15 +0200915void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
916 struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100917void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
918 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100919int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100920 struct amdgpu_sync *sync, struct fence *fence,
Chunming Zhoufd53be32016-07-01 17:59:01 +0800921 struct amdgpu_job *job);
922int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
Christian König971fe9a92016-03-01 15:09:25 +0100923void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian König8b4fb002015-11-15 16:04:16 +0100924int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
925 struct amdgpu_vm *vm);
926int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
927 struct amdgpu_vm *vm);
928int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
929 struct amdgpu_sync *sync);
930int amdgpu_vm_bo_update(struct amdgpu_device *adev,
931 struct amdgpu_bo_va *bo_va,
Christian König99e124f2016-08-16 14:43:17 +0200932 bool clear);
Christian König8b4fb002015-11-15 16:04:16 +0100933void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
934 struct amdgpu_bo *bo);
935struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
936 struct amdgpu_bo *bo);
937struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
938 struct amdgpu_vm *vm,
939 struct amdgpu_bo *bo);
940int amdgpu_vm_bo_map(struct amdgpu_device *adev,
941 struct amdgpu_bo_va *bo_va,
942 uint64_t addr, uint64_t offset,
943 uint64_t size, uint32_t flags);
944int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
945 struct amdgpu_bo_va *bo_va,
946 uint64_t addr);
947void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
948 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100949
Alex Deucher97b2e202015-04-20 16:51:00 -0400950/*
951 * context related structures
952 */
953
Christian König21c16bf2015-07-07 17:24:49 +0200954struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200955 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800956 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200957 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200958};
959
Alex Deucher97b2e202015-04-20 16:51:00 -0400960struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400961 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800962 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400963 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200964 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800965 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200966 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400967};
968
969struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400970 struct amdgpu_device *adev;
971 struct mutex lock;
972 /* protected by lock */
973 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400974};
975
Alex Deucher0b492a42015-08-16 22:48:26 -0400976struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
977int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
978
Christian König21c16bf2015-07-07 17:24:49 +0200979uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200980 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200981struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
982 struct amdgpu_ring *ring, uint64_t seq);
983
Alex Deucher0b492a42015-08-16 22:48:26 -0400984int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
985 struct drm_file *filp);
986
Christian Königefd4ccb2015-08-04 16:20:31 +0200987void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
988void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400989
Alex Deucher97b2e202015-04-20 16:51:00 -0400990/*
991 * file private structure
992 */
993
994struct amdgpu_fpriv {
995 struct amdgpu_vm vm;
996 struct mutex bo_list_lock;
997 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -0400998 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400999};
1000
1001/*
1002 * residency list
1003 */
1004
1005struct amdgpu_bo_list {
1006 struct mutex lock;
1007 struct amdgpu_bo *gds_obj;
1008 struct amdgpu_bo *gws_obj;
1009 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001010 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001011 unsigned num_entries;
1012 struct amdgpu_bo_list_entry *array;
1013};
1014
1015struct amdgpu_bo_list *
1016amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001017void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1018 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001019void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1020void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1021
1022/*
1023 * GFX stuff
1024 */
1025#include "clearstate_defs.h"
1026
Alex Deucher79e54122016-04-08 15:45:13 -04001027struct amdgpu_rlc_funcs {
1028 void (*enter_safe_mode)(struct amdgpu_device *adev);
1029 void (*exit_safe_mode)(struct amdgpu_device *adev);
1030};
1031
Alex Deucher97b2e202015-04-20 16:51:00 -04001032struct amdgpu_rlc {
1033 /* for power gating */
1034 struct amdgpu_bo *save_restore_obj;
1035 uint64_t save_restore_gpu_addr;
1036 volatile uint32_t *sr_ptr;
1037 const u32 *reg_list;
1038 u32 reg_list_size;
1039 /* for clear state */
1040 struct amdgpu_bo *clear_state_obj;
1041 uint64_t clear_state_gpu_addr;
1042 volatile uint32_t *cs_ptr;
1043 const struct cs_section_def *cs_data;
1044 u32 clear_state_size;
1045 /* for cp tables */
1046 struct amdgpu_bo *cp_table_obj;
1047 uint64_t cp_table_gpu_addr;
1048 volatile uint32_t *cp_table_ptr;
1049 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001050
1051 /* safe mode for updating CG/PG state */
1052 bool in_safe_mode;
1053 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001054
1055 /* for firmware data */
1056 u32 save_and_restore_offset;
1057 u32 clear_state_descriptor_offset;
1058 u32 avail_scratch_ram_locations;
1059 u32 reg_restore_list_size;
1060 u32 reg_list_format_start;
1061 u32 reg_list_format_separate_start;
1062 u32 starting_offsets_start;
1063 u32 reg_list_format_size_bytes;
1064 u32 reg_list_size_bytes;
1065
1066 u32 *register_list_format;
1067 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001068};
1069
1070struct amdgpu_mec {
1071 struct amdgpu_bo *hpd_eop_obj;
1072 u64 hpd_eop_gpu_addr;
1073 u32 num_pipe;
1074 u32 num_mec;
1075 u32 num_queue;
1076};
1077
1078/*
1079 * GPU scratch registers structures, functions & helpers
1080 */
1081struct amdgpu_scratch {
1082 unsigned num_reg;
1083 uint32_t reg_base;
1084 bool free[32];
1085 uint32_t reg[32];
1086};
1087
1088/*
1089 * GFX configurations
1090 */
1091struct amdgpu_gca_config {
1092 unsigned max_shader_engines;
1093 unsigned max_tile_pipes;
1094 unsigned max_cu_per_sh;
1095 unsigned max_sh_per_se;
1096 unsigned max_backends_per_se;
1097 unsigned max_texture_channel_caches;
1098 unsigned max_gprs;
1099 unsigned max_gs_threads;
1100 unsigned max_hw_contexts;
1101 unsigned sc_prim_fifo_size_frontend;
1102 unsigned sc_prim_fifo_size_backend;
1103 unsigned sc_hiz_tile_fifo_size;
1104 unsigned sc_earlyz_tile_fifo_size;
1105
1106 unsigned num_tile_pipes;
1107 unsigned backend_enable_mask;
1108 unsigned mem_max_burst_length_bytes;
1109 unsigned mem_row_size_in_kb;
1110 unsigned shader_engine_tile_size;
1111 unsigned num_gpus;
1112 unsigned multi_gpu_tile_size;
1113 unsigned mc_arb_ramcfg;
1114 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001115 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001116
1117 uint32_t tile_mode_array[32];
1118 uint32_t macrotile_mode_array[16];
1119};
1120
Alex Deucher7dae69a2016-05-03 16:25:53 -04001121struct amdgpu_cu_info {
1122 uint32_t number; /* total active CU number */
1123 uint32_t ao_cu_mask;
1124 uint32_t bitmap[4][4];
1125};
1126
Alex Deucherb95e31f2016-07-07 15:01:42 -04001127struct amdgpu_gfx_funcs {
1128 /* get the gpu clock counter */
1129 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -04001130 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -04001131};
1132
Alex Deucher97b2e202015-04-20 16:51:00 -04001133struct amdgpu_gfx {
1134 struct mutex gpu_clock_mutex;
1135 struct amdgpu_gca_config config;
1136 struct amdgpu_rlc rlc;
1137 struct amdgpu_mec mec;
1138 struct amdgpu_scratch scratch;
1139 const struct firmware *me_fw; /* ME firmware */
1140 uint32_t me_fw_version;
1141 const struct firmware *pfp_fw; /* PFP firmware */
1142 uint32_t pfp_fw_version;
1143 const struct firmware *ce_fw; /* CE firmware */
1144 uint32_t ce_fw_version;
1145 const struct firmware *rlc_fw; /* RLC firmware */
1146 uint32_t rlc_fw_version;
1147 const struct firmware *mec_fw; /* MEC firmware */
1148 uint32_t mec_fw_version;
1149 const struct firmware *mec2_fw; /* MEC2 firmware */
1150 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001151 uint32_t me_feature_version;
1152 uint32_t ce_feature_version;
1153 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001154 uint32_t rlc_feature_version;
1155 uint32_t mec_feature_version;
1156 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001157 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1158 unsigned num_gfx_rings;
1159 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1160 unsigned num_compute_rings;
1161 struct amdgpu_irq_src eop_irq;
1162 struct amdgpu_irq_src priv_reg_irq;
1163 struct amdgpu_irq_src priv_inst_irq;
1164 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001165 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001166 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001167 unsigned ce_ram_size;
1168 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001169 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001170
1171 /* reset mask */
1172 uint32_t grbm_soft_reset;
1173 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001174};
1175
Christian Königb07c60c2016-01-31 12:29:04 +01001176int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001177 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001178void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1179 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001180int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001181 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001182 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001183int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1184void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1185int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001186int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001187void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001188void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001189void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001190void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001191int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1192 unsigned ring_size, u32 nop, u32 align_mask,
1193 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1194 enum amdgpu_ring_type ring_type);
1195void amdgpu_ring_fini(struct amdgpu_ring *ring);
1196
1197/*
1198 * CS.
1199 */
1200struct amdgpu_cs_chunk {
1201 uint32_t chunk_id;
1202 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001203 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001204};
1205
1206struct amdgpu_cs_parser {
1207 struct amdgpu_device *adev;
1208 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001209 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001210
Alex Deucher97b2e202015-04-20 16:51:00 -04001211 /* chunks */
1212 unsigned nchunks;
1213 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001214
Christian König50838c82016-02-03 13:44:52 +01001215 /* scheduler job object */
1216 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001217
Christian Königc3cca412015-12-15 14:41:33 +01001218 /* buffer objects */
1219 struct ww_acquire_ctx ticket;
1220 struct amdgpu_bo_list *bo_list;
1221 struct amdgpu_bo_list_entry vm_pd;
1222 struct list_head validated;
1223 struct fence *fence;
1224 uint64_t bytes_moved_threshold;
1225 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001226
1227 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001228 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001229};
1230
Chunming Zhoubb977d32015-08-18 15:16:40 +08001231struct amdgpu_job {
1232 struct amd_sched_job base;
1233 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001234 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001235 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001236 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001237 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001238 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001239 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001240 void *owner;
Christian König92f25092016-05-06 15:57:42 +02001241 uint64_t ctx;
Chunming Zhoufd53be32016-07-01 17:59:01 +08001242 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001243 unsigned vm_id;
1244 uint64_t vm_pd_addr;
1245 uint32_t gds_base, gds_size;
1246 uint32_t gws_base, gws_size;
1247 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001248
1249 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001250 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001251 uint64_t uf_sequence;
1252
Chunming Zhoubb977d32015-08-18 15:16:40 +08001253};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001254#define to_amdgpu_job(sched_job) \
1255 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001256
Christian König7270f832016-01-31 11:00:41 +01001257static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1258 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001259{
Christian König50838c82016-02-03 13:44:52 +01001260 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001261}
1262
Christian König7270f832016-01-31 11:00:41 +01001263static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1264 uint32_t ib_idx, int idx,
1265 uint32_t value)
1266{
Christian König50838c82016-02-03 13:44:52 +01001267 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001268}
1269
Alex Deucher97b2e202015-04-20 16:51:00 -04001270/*
1271 * Writeback
1272 */
1273#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1274
1275struct amdgpu_wb {
1276 struct amdgpu_bo *wb_obj;
1277 volatile uint32_t *wb;
1278 uint64_t gpu_addr;
1279 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1280 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1281};
1282
1283int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1284void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1285
Alex Deucher97b2e202015-04-20 16:51:00 -04001286
Alex Deucher97b2e202015-04-20 16:51:00 -04001287
1288enum amdgpu_int_thermal_type {
1289 THERMAL_TYPE_NONE,
1290 THERMAL_TYPE_EXTERNAL,
1291 THERMAL_TYPE_EXTERNAL_GPIO,
1292 THERMAL_TYPE_RV6XX,
1293 THERMAL_TYPE_RV770,
1294 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1295 THERMAL_TYPE_EVERGREEN,
1296 THERMAL_TYPE_SUMO,
1297 THERMAL_TYPE_NI,
1298 THERMAL_TYPE_SI,
1299 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1300 THERMAL_TYPE_CI,
1301 THERMAL_TYPE_KV,
1302};
1303
1304enum amdgpu_dpm_auto_throttle_src {
1305 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1306 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1307};
1308
1309enum amdgpu_dpm_event_src {
1310 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1311 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1312 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1313 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1314 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1315};
1316
1317#define AMDGPU_MAX_VCE_LEVELS 6
1318
1319enum amdgpu_vce_level {
1320 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1321 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1322 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1323 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1324 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1325 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1326};
1327
1328struct amdgpu_ps {
1329 u32 caps; /* vbios flags */
1330 u32 class; /* vbios flags */
1331 u32 class2; /* vbios flags */
1332 /* UVD clocks */
1333 u32 vclk;
1334 u32 dclk;
1335 /* VCE clocks */
1336 u32 evclk;
1337 u32 ecclk;
1338 bool vce_active;
1339 enum amdgpu_vce_level vce_level;
1340 /* asic priv */
1341 void *ps_priv;
1342};
1343
1344struct amdgpu_dpm_thermal {
1345 /* thermal interrupt work */
1346 struct work_struct work;
1347 /* low temperature threshold */
1348 int min_temp;
1349 /* high temperature threshold */
1350 int max_temp;
1351 /* was last interrupt low to high or high to low */
1352 bool high_to_low;
1353 /* interrupt source */
1354 struct amdgpu_irq_src irq;
1355};
1356
1357enum amdgpu_clk_action
1358{
1359 AMDGPU_SCLK_UP = 1,
1360 AMDGPU_SCLK_DOWN
1361};
1362
1363struct amdgpu_blacklist_clocks
1364{
1365 u32 sclk;
1366 u32 mclk;
1367 enum amdgpu_clk_action action;
1368};
1369
1370struct amdgpu_clock_and_voltage_limits {
1371 u32 sclk;
1372 u32 mclk;
1373 u16 vddc;
1374 u16 vddci;
1375};
1376
1377struct amdgpu_clock_array {
1378 u32 count;
1379 u32 *values;
1380};
1381
1382struct amdgpu_clock_voltage_dependency_entry {
1383 u32 clk;
1384 u16 v;
1385};
1386
1387struct amdgpu_clock_voltage_dependency_table {
1388 u32 count;
1389 struct amdgpu_clock_voltage_dependency_entry *entries;
1390};
1391
1392union amdgpu_cac_leakage_entry {
1393 struct {
1394 u16 vddc;
1395 u32 leakage;
1396 };
1397 struct {
1398 u16 vddc1;
1399 u16 vddc2;
1400 u16 vddc3;
1401 };
1402};
1403
1404struct amdgpu_cac_leakage_table {
1405 u32 count;
1406 union amdgpu_cac_leakage_entry *entries;
1407};
1408
1409struct amdgpu_phase_shedding_limits_entry {
1410 u16 voltage;
1411 u32 sclk;
1412 u32 mclk;
1413};
1414
1415struct amdgpu_phase_shedding_limits_table {
1416 u32 count;
1417 struct amdgpu_phase_shedding_limits_entry *entries;
1418};
1419
1420struct amdgpu_uvd_clock_voltage_dependency_entry {
1421 u32 vclk;
1422 u32 dclk;
1423 u16 v;
1424};
1425
1426struct amdgpu_uvd_clock_voltage_dependency_table {
1427 u8 count;
1428 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1429};
1430
1431struct amdgpu_vce_clock_voltage_dependency_entry {
1432 u32 ecclk;
1433 u32 evclk;
1434 u16 v;
1435};
1436
1437struct amdgpu_vce_clock_voltage_dependency_table {
1438 u8 count;
1439 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1440};
1441
1442struct amdgpu_ppm_table {
1443 u8 ppm_design;
1444 u16 cpu_core_number;
1445 u32 platform_tdp;
1446 u32 small_ac_platform_tdp;
1447 u32 platform_tdc;
1448 u32 small_ac_platform_tdc;
1449 u32 apu_tdp;
1450 u32 dgpu_tdp;
1451 u32 dgpu_ulv_power;
1452 u32 tj_max;
1453};
1454
1455struct amdgpu_cac_tdp_table {
1456 u16 tdp;
1457 u16 configurable_tdp;
1458 u16 tdc;
1459 u16 battery_power_limit;
1460 u16 small_power_limit;
1461 u16 low_cac_leakage;
1462 u16 high_cac_leakage;
1463 u16 maximum_power_delivery_limit;
1464};
1465
1466struct amdgpu_dpm_dynamic_state {
1467 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1468 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1469 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1470 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1471 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1472 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1473 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1474 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1475 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1476 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1477 struct amdgpu_clock_array valid_sclk_values;
1478 struct amdgpu_clock_array valid_mclk_values;
1479 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1480 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1481 u32 mclk_sclk_ratio;
1482 u32 sclk_mclk_delta;
1483 u16 vddc_vddci_delta;
1484 u16 min_vddc_for_pcie_gen2;
1485 struct amdgpu_cac_leakage_table cac_leakage_table;
1486 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1487 struct amdgpu_ppm_table *ppm_table;
1488 struct amdgpu_cac_tdp_table *cac_tdp_table;
1489};
1490
1491struct amdgpu_dpm_fan {
1492 u16 t_min;
1493 u16 t_med;
1494 u16 t_high;
1495 u16 pwm_min;
1496 u16 pwm_med;
1497 u16 pwm_high;
1498 u8 t_hyst;
1499 u32 cycle_delay;
1500 u16 t_max;
1501 u8 control_mode;
1502 u16 default_max_fan_pwm;
1503 u16 default_fan_output_sensitivity;
1504 u16 fan_output_sensitivity;
1505 bool ucode_fan_control;
1506};
1507
1508enum amdgpu_pcie_gen {
1509 AMDGPU_PCIE_GEN1 = 0,
1510 AMDGPU_PCIE_GEN2 = 1,
1511 AMDGPU_PCIE_GEN3 = 2,
1512 AMDGPU_PCIE_GEN_INVALID = 0xffff
1513};
1514
1515enum amdgpu_dpm_forced_level {
1516 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1517 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1518 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001519 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001520};
1521
1522struct amdgpu_vce_state {
1523 /* vce clocks */
1524 u32 evclk;
1525 u32 ecclk;
1526 /* gpu clocks */
1527 u32 sclk;
1528 u32 mclk;
1529 u8 clk_idx;
1530 u8 pstate;
1531};
1532
1533struct amdgpu_dpm_funcs {
1534 int (*get_temperature)(struct amdgpu_device *adev);
1535 int (*pre_set_power_state)(struct amdgpu_device *adev);
1536 int (*set_power_state)(struct amdgpu_device *adev);
1537 void (*post_set_power_state)(struct amdgpu_device *adev);
1538 void (*display_configuration_changed)(struct amdgpu_device *adev);
1539 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1540 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1541 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1542 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1543 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1544 bool (*vblank_too_short)(struct amdgpu_device *adev);
1545 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001546 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001547 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1548 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1549 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1550 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1551 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001552 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1553 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001554 int (*get_sclk_od)(struct amdgpu_device *adev);
1555 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001556 int (*get_mclk_od)(struct amdgpu_device *adev);
1557 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001558};
1559
1560struct amdgpu_dpm {
1561 struct amdgpu_ps *ps;
1562 /* number of valid power states */
1563 int num_ps;
1564 /* current power state that is active */
1565 struct amdgpu_ps *current_ps;
1566 /* requested power state */
1567 struct amdgpu_ps *requested_ps;
1568 /* boot up power state */
1569 struct amdgpu_ps *boot_ps;
1570 /* default uvd power state */
1571 struct amdgpu_ps *uvd_ps;
1572 /* vce requirements */
1573 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1574 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001575 enum amd_pm_state_type state;
1576 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001577 u32 platform_caps;
1578 u32 voltage_response_time;
1579 u32 backbias_response_time;
1580 void *priv;
1581 u32 new_active_crtcs;
1582 int new_active_crtc_count;
1583 u32 current_active_crtcs;
1584 int current_active_crtc_count;
1585 struct amdgpu_dpm_dynamic_state dyn_state;
1586 struct amdgpu_dpm_fan fan;
1587 u32 tdp_limit;
1588 u32 near_tdp_limit;
1589 u32 near_tdp_limit_adjusted;
1590 u32 sq_ramping_threshold;
1591 u32 cac_leakage;
1592 u16 tdp_od_limit;
1593 u32 tdp_adjustment;
1594 u16 load_line_slope;
1595 bool power_control;
1596 bool ac_power;
1597 /* special states active */
1598 bool thermal_active;
1599 bool uvd_active;
1600 bool vce_active;
1601 /* thermal handling */
1602 struct amdgpu_dpm_thermal thermal;
1603 /* forced levels */
1604 enum amdgpu_dpm_forced_level forced_level;
1605};
1606
1607struct amdgpu_pm {
1608 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001609 u32 current_sclk;
1610 u32 current_mclk;
1611 u32 default_sclk;
1612 u32 default_mclk;
1613 struct amdgpu_i2c_chan *i2c_bus;
1614 /* internal thermal controller on rv6xx+ */
1615 enum amdgpu_int_thermal_type int_thermal_type;
1616 struct device *int_hwmon_dev;
1617 /* fan control parameters */
1618 bool no_fan;
1619 u8 fan_pulses_per_revolution;
1620 u8 fan_min_rpm;
1621 u8 fan_max_rpm;
1622 /* dpm */
1623 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001624 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001625 struct amdgpu_dpm dpm;
1626 const struct firmware *fw; /* SMC firmware */
1627 uint32_t fw_version;
1628 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001629 uint32_t pcie_gen_mask;
1630 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001631 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001632};
1633
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001634void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1635
Alex Deucher97b2e202015-04-20 16:51:00 -04001636/*
1637 * UVD
1638 */
Arindam Nathc0365542016-04-12 13:46:15 +02001639#define AMDGPU_DEFAULT_UVD_HANDLES 10
1640#define AMDGPU_MAX_UVD_HANDLES 40
1641#define AMDGPU_UVD_STACK_SIZE (200*1024)
1642#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1643#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1644#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001645
1646struct amdgpu_uvd {
1647 struct amdgpu_bo *vcpu_bo;
1648 void *cpu_addr;
1649 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001650 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001651 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001652 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001653 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1654 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1655 struct delayed_work idle_work;
1656 const struct firmware *fw; /* UVD firmware */
1657 struct amdgpu_ring ring;
1658 struct amdgpu_irq_src irq;
1659 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001660 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001661 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001662 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001663};
1664
1665/*
1666 * VCE
1667 */
1668#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001669#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1670
Alex Deucher6a585772015-07-10 14:16:24 -04001671#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1672#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1673
Alex Deucher97b2e202015-04-20 16:51:00 -04001674struct amdgpu_vce {
1675 struct amdgpu_bo *vcpu_bo;
1676 uint64_t gpu_addr;
1677 unsigned fw_version;
1678 unsigned fb_version;
1679 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1680 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001681 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001682 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001683 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001684 const struct firmware *fw; /* VCE firmware */
1685 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1686 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001687 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001688 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001689 uint32_t srbm_soft_reset;
Alex Deucher75c65482016-08-24 16:56:21 -04001690 unsigned num_rings;
Alex Deucher97b2e202015-04-20 16:51:00 -04001691};
1692
1693/*
1694 * SDMA
1695 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001696struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001697 /* SDMA firmware */
1698 const struct firmware *fw;
1699 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001700 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001701
1702 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001703 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001704};
1705
Alex Deucherc113ea12015-10-08 16:30:37 -04001706struct amdgpu_sdma {
1707 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1708 struct amdgpu_irq_src trap_irq;
1709 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001710 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001711 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001712};
1713
Alex Deucher97b2e202015-04-20 16:51:00 -04001714/*
1715 * Firmware
1716 */
1717struct amdgpu_firmware {
1718 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1719 bool smu_load;
1720 struct amdgpu_bo *fw_buf;
1721 unsigned int fw_size;
1722};
1723
1724/*
1725 * Benchmarking
1726 */
1727void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1728
1729
1730/*
1731 * Testing
1732 */
1733void amdgpu_test_moves(struct amdgpu_device *adev);
1734void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1735 struct amdgpu_ring *cpA,
1736 struct amdgpu_ring *cpB);
1737void amdgpu_test_syncing(struct amdgpu_device *adev);
1738
1739/*
1740 * MMU Notifier
1741 */
1742#if defined(CONFIG_MMU_NOTIFIER)
1743int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1744void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1745#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001746static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001747{
1748 return -ENODEV;
1749}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001750static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001751#endif
1752
1753/*
1754 * Debugfs
1755 */
1756struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001757 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001758 unsigned num_files;
1759};
1760
1761int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001762 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001763 unsigned nfiles);
1764int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1765
1766#if defined(CONFIG_DEBUG_FS)
1767int amdgpu_debugfs_init(struct drm_minor *minor);
1768void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1769#endif
1770
Huang Rui50ab2532016-06-12 15:51:09 +08001771int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1772
Alex Deucher97b2e202015-04-20 16:51:00 -04001773/*
1774 * amdgpu smumgr functions
1775 */
1776struct amdgpu_smumgr_funcs {
1777 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1778 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1779 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1780};
1781
1782/*
1783 * amdgpu smumgr
1784 */
1785struct amdgpu_smumgr {
1786 struct amdgpu_bo *toc_buf;
1787 struct amdgpu_bo *smu_buf;
1788 /* asic priv smu data */
1789 void *priv;
1790 spinlock_t smu_lock;
1791 /* smumgr functions */
1792 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1793 /* ucode loading complete flag */
1794 uint32_t fw_flags;
1795};
1796
1797/*
1798 * ASIC specific register table accessible by UMD
1799 */
1800struct amdgpu_allowed_register_entry {
1801 uint32_t reg_offset;
1802 bool untouched;
1803 bool grbm_indexed;
1804};
1805
Alex Deucher97b2e202015-04-20 16:51:00 -04001806/*
1807 * ASIC specific functions.
1808 */
1809struct amdgpu_asic_funcs {
1810 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001811 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1812 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001813 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1814 u32 sh_num, u32 reg_offset, u32 *value);
1815 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1816 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001817 /* get the reference clock */
1818 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001819 /* MM block clocks */
1820 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1821 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Andres Rodriguez048765a2016-06-11 02:51:32 -04001822 /* query virtual capabilities */
1823 u32 (*get_virtual_caps)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001824};
1825
1826/*
1827 * IOCTL.
1828 */
1829int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1830 struct drm_file *filp);
1831int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1832 struct drm_file *filp);
1833
1834int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1835 struct drm_file *filp);
1836int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1837 struct drm_file *filp);
1838int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1839 struct drm_file *filp);
1840int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1841 struct drm_file *filp);
1842int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1843 struct drm_file *filp);
1844int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1845 struct drm_file *filp);
1846int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1847int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1848
1849int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1850 struct drm_file *filp);
1851
1852/* VRAM scratch page for HDP bug, default vram page */
1853struct amdgpu_vram_scratch {
1854 struct amdgpu_bo *robj;
1855 volatile uint32_t *ptr;
1856 u64 gpu_addr;
1857};
1858
1859/*
1860 * ACPI
1861 */
1862struct amdgpu_atif_notification_cfg {
1863 bool enabled;
1864 int command_code;
1865};
1866
1867struct amdgpu_atif_notifications {
1868 bool display_switch;
1869 bool expansion_mode_change;
1870 bool thermal_state;
1871 bool forced_power_state;
1872 bool system_power_state;
1873 bool display_conf_change;
1874 bool px_gfx_switch;
1875 bool brightness_change;
1876 bool dgpu_display_event;
1877};
1878
1879struct amdgpu_atif_functions {
1880 bool system_params;
1881 bool sbios_requests;
1882 bool select_active_disp;
1883 bool lid_state;
1884 bool get_tv_standard;
1885 bool set_tv_standard;
1886 bool get_panel_expansion_mode;
1887 bool set_panel_expansion_mode;
1888 bool temperature_change;
1889 bool graphics_device_types;
1890};
1891
1892struct amdgpu_atif {
1893 struct amdgpu_atif_notifications notifications;
1894 struct amdgpu_atif_functions functions;
1895 struct amdgpu_atif_notification_cfg notification_cfg;
1896 struct amdgpu_encoder *encoder_for_bl;
1897};
1898
1899struct amdgpu_atcs_functions {
1900 bool get_ext_state;
1901 bool pcie_perf_req;
1902 bool pcie_dev_rdy;
1903 bool pcie_bus_width;
1904};
1905
1906struct amdgpu_atcs {
1907 struct amdgpu_atcs_functions functions;
1908};
1909
Alex Deucher97b2e202015-04-20 16:51:00 -04001910/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001911 * CGS
1912 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001913struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1914void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001915
1916
Alex Deucher7e471e62016-02-01 11:13:04 -05001917/* GPU virtualization */
Andres Rodriguez048765a2016-06-11 02:51:32 -04001918#define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0)
1919#define AMDGPU_VIRT_CAPS_IS_VF (1 << 1)
Alex Deucher7e471e62016-02-01 11:13:04 -05001920struct amdgpu_virtualization {
1921 bool supports_sr_iov;
Andres Rodriguez048765a2016-06-11 02:51:32 -04001922 bool is_virtual;
1923 u32 caps;
Alex Deucher7e471e62016-02-01 11:13:04 -05001924};
1925
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001926/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001927 * Core structure, functions and helpers.
1928 */
1929typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1930typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1931
1932typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1933typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1934
Alex Deucher8faf0e02015-07-28 11:50:31 -04001935struct amdgpu_ip_block_status {
1936 bool valid;
1937 bool sw;
1938 bool hw;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001939 bool hang;
Alex Deucher8faf0e02015-07-28 11:50:31 -04001940};
1941
Alex Deucher97b2e202015-04-20 16:51:00 -04001942struct amdgpu_device {
1943 struct device *dev;
1944 struct drm_device *ddev;
1945 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001946
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001947#ifdef CONFIG_DRM_AMD_ACP
1948 struct amdgpu_acp acp;
1949#endif
1950
Alex Deucher97b2e202015-04-20 16:51:00 -04001951 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001952 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001953 uint32_t family;
1954 uint32_t rev_id;
1955 uint32_t external_rev_id;
1956 unsigned long flags;
1957 int usec_timeout;
1958 const struct amdgpu_asic_funcs *asic_funcs;
1959 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001960 bool need_dma32;
1961 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001962 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001963 struct notifier_block acpi_nb;
1964 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1965 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001966 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001967#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001968 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001969#endif
1970 struct amdgpu_atif atif;
1971 struct amdgpu_atcs atcs;
1972 struct mutex srbm_mutex;
1973 /* GRBM index mutex. Protects concurrent access to GRBM index */
1974 struct mutex grbm_idx_mutex;
1975 struct dev_pm_domain vga_pm_domain;
1976 bool have_disp_power_ref;
1977
1978 /* BIOS */
1979 uint8_t *bios;
1980 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001981 struct amdgpu_bo *stollen_vga_memory;
1982 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1983
1984 /* Register/doorbell mmio */
1985 resource_size_t rmmio_base;
1986 resource_size_t rmmio_size;
1987 void __iomem *rmmio;
1988 /* protects concurrent MM_INDEX/DATA based register access */
1989 spinlock_t mmio_idx_lock;
1990 /* protects concurrent SMC based register access */
1991 spinlock_t smc_idx_lock;
1992 amdgpu_rreg_t smc_rreg;
1993 amdgpu_wreg_t smc_wreg;
1994 /* protects concurrent PCIE register access */
1995 spinlock_t pcie_idx_lock;
1996 amdgpu_rreg_t pcie_rreg;
1997 amdgpu_wreg_t pcie_wreg;
1998 /* protects concurrent UVD register access */
1999 spinlock_t uvd_ctx_idx_lock;
2000 amdgpu_rreg_t uvd_ctx_rreg;
2001 amdgpu_wreg_t uvd_ctx_wreg;
2002 /* protects concurrent DIDT register access */
2003 spinlock_t didt_idx_lock;
2004 amdgpu_rreg_t didt_rreg;
2005 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08002006 /* protects concurrent gc_cac register access */
2007 spinlock_t gc_cac_idx_lock;
2008 amdgpu_rreg_t gc_cac_rreg;
2009 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04002010 /* protects concurrent ENDPOINT (audio) register access */
2011 spinlock_t audio_endpt_idx_lock;
2012 amdgpu_block_rreg_t audio_endpt_rreg;
2013 amdgpu_block_wreg_t audio_endpt_wreg;
2014 void __iomem *rio_mem;
2015 resource_size_t rio_mem_size;
2016 struct amdgpu_doorbell doorbell;
2017
2018 /* clock/pll info */
2019 struct amdgpu_clock clock;
2020
2021 /* MC */
2022 struct amdgpu_mc mc;
2023 struct amdgpu_gart gart;
2024 struct amdgpu_dummy_page dummy_page;
2025 struct amdgpu_vm_manager vm_manager;
2026
2027 /* memory management */
2028 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002029 struct amdgpu_vram_scratch vram_scratch;
2030 struct amdgpu_wb wb;
2031 atomic64_t vram_usage;
2032 atomic64_t vram_vis_usage;
2033 atomic64_t gtt_usage;
2034 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02002035 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02002036 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002037
Marek Olšák95844d22016-08-17 23:49:27 +02002038 /* data for buffer migration throttling */
2039 struct {
2040 spinlock_t lock;
2041 s64 last_update_us;
2042 s64 accum_us; /* accumulated microseconds */
2043 u32 log2_max_MBps;
2044 } mm_stats;
2045
Alex Deucher97b2e202015-04-20 16:51:00 -04002046 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08002047 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04002048 struct amdgpu_mode_info mode_info;
2049 struct work_struct hotplug_work;
2050 struct amdgpu_irq_src crtc_irq;
2051 struct amdgpu_irq_src pageflip_irq;
2052 struct amdgpu_irq_src hpd_irq;
2053
2054 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02002055 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002056 unsigned num_rings;
2057 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2058 bool ib_pool_ready;
2059 struct amdgpu_sa_manager ring_tmp_bo;
2060
2061 /* interrupts */
2062 struct amdgpu_irq irq;
2063
Alex Deucher1f7371b2015-12-02 17:46:21 -05002064 /* powerplay */
2065 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002066 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002067 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002068
Alex Deucher97b2e202015-04-20 16:51:00 -04002069 /* dpm */
2070 struct amdgpu_pm pm;
2071 u32 cg_flags;
2072 u32 pg_flags;
2073
2074 /* amdgpu smumgr */
2075 struct amdgpu_smumgr smu;
2076
2077 /* gfx */
2078 struct amdgpu_gfx gfx;
2079
2080 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002081 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002082
2083 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002084 struct amdgpu_uvd uvd;
2085
2086 /* vce */
2087 struct amdgpu_vce vce;
2088
2089 /* firmwares */
2090 struct amdgpu_firmware firmware;
2091
2092 /* GDS */
2093 struct amdgpu_gds gds;
2094
2095 const struct amdgpu_ip_block_version *ip_blocks;
2096 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002097 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002098 struct mutex mn_lock;
2099 DECLARE_HASHTABLE(mn_hash, 7);
2100
2101 /* tracking pinned memory */
2102 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002103 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002104 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002105
2106 /* amdkfd interface */
2107 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002108
Alex Deucher7e471e62016-02-01 11:13:04 -05002109 struct amdgpu_virtualization virtualization;
Chunming Zhou0c4e7fa2016-08-17 11:41:30 +08002110
2111 /* link all shadow bo */
2112 struct list_head shadow_list;
2113 struct mutex shadow_list_lock;
Alex Deucher97b2e202015-04-20 16:51:00 -04002114};
2115
2116bool amdgpu_device_is_px(struct drm_device *dev);
2117int amdgpu_device_init(struct amdgpu_device *adev,
2118 struct drm_device *ddev,
2119 struct pci_dev *pdev,
2120 uint32_t flags);
2121void amdgpu_device_fini(struct amdgpu_device *adev);
2122int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2123
2124uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2125 bool always_indirect);
2126void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2127 bool always_indirect);
2128u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2129void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2130
2131u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2132void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2133
2134/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002135 * Registers read & write functions.
2136 */
2137#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2138#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2139#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2140#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2141#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2142#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2143#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2144#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2145#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2146#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2147#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2148#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2149#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2150#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2151#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08002152#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2153#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002154#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2155#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2156#define WREG32_P(reg, val, mask) \
2157 do { \
2158 uint32_t tmp_ = RREG32(reg); \
2159 tmp_ &= (mask); \
2160 tmp_ |= ((val) & ~(mask)); \
2161 WREG32(reg, tmp_); \
2162 } while (0)
2163#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2164#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2165#define WREG32_PLL_P(reg, val, mask) \
2166 do { \
2167 uint32_t tmp_ = RREG32_PLL(reg); \
2168 tmp_ &= (mask); \
2169 tmp_ |= ((val) & ~(mask)); \
2170 WREG32_PLL(reg, tmp_); \
2171 } while (0)
2172#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2173#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2174#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2175
2176#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2177#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2178
2179#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2180#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2181
2182#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2183 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2184 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2185
2186#define REG_GET_FIELD(value, reg, field) \
2187 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2188
Tom St Denis61cb8ce2016-08-09 10:13:21 -04002189#define WREG32_FIELD(reg, field, val) \
2190 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
2191
Alex Deucher97b2e202015-04-20 16:51:00 -04002192/*
2193 * BIOS helpers.
2194 */
2195#define RBIOS8(i) (adev->bios[i])
2196#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2197#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2198
2199/*
2200 * RING helpers.
2201 */
2202static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2203{
2204 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002205 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002206 ring->ring[ring->wptr++] = v;
2207 ring->wptr &= ring->ptr_mask;
2208 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002209}
2210
Alex Deucherc113ea12015-10-08 16:30:37 -04002211static inline struct amdgpu_sdma_instance *
2212amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002213{
2214 struct amdgpu_device *adev = ring->adev;
2215 int i;
2216
Alex Deucherc113ea12015-10-08 16:30:37 -04002217 for (i = 0; i < adev->sdma.num_instances; i++)
2218 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002219 break;
2220
2221 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002222 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002223 else
2224 return NULL;
2225}
2226
Alex Deucher97b2e202015-04-20 16:51:00 -04002227/*
2228 * ASICs macro.
2229 */
2230#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2231#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002232#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2233#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2234#define amdgpu_asic_set_vce_clocks(adev, ev, ec) (adev)->asic_funcs->set_vce_clocks((adev), (ev), (ec))
Andres Rodriguez048765a2016-06-11 02:51:32 -04002235#define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002236#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002237#define amdgpu_asic_read_bios_from_rom(adev, b, l) (adev)->asic_funcs->read_bios_from_rom((adev), (b), (l))
Alex Deucher97b2e202015-04-20 16:51:00 -04002238#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 -04002239#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2240#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2241#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 +02002242#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 -04002243#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 -04002244#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2245#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02002246#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04002247#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2248#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2249#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002250#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 +01002251#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002252#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002253#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002254#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 +02002255#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002256#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002257#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002258#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2259#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002260#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2261#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2262#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2263#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2264#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2265#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2266#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2267#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2268#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2269#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2270#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2271#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2272#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002273#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 -04002274#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2275#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2276#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))
2277#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2278#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002279#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 +08002280#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 -04002281#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2282#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2283#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2284#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002285#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002286#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002287#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04002288#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04002289#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 +08002290
2291#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002292 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002293 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002294 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002295
2296#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002297 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002298 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002299 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002300
2301#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002302 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002303 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002304 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002305
2306#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002307 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002308 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002309 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002310
2311#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002312 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002313 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002314 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002315
Rex Zhu1b5708f2015-11-10 18:25:24 -05002316#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002317 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002318 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002319 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002320
2321#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002322 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002323 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002324 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002325
2326
2327#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002328 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002329 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002330 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002331
2332#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002333 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002334 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002335 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002336
2337#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002338 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002339 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002340 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002341
2342#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002343 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002344 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002345 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002346
2347#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002348 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002349
2350#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002351 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002352
Eric Huangf3898ea2015-12-11 16:24:34 -05002353#define amdgpu_dpm_get_pp_num_states(adev, data) \
2354 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2355
2356#define amdgpu_dpm_get_pp_table(adev, table) \
2357 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2358
2359#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2360 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2361
2362#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2363 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2364
2365#define amdgpu_dpm_force_clock_level(adev, type, level) \
2366 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2367
Eric Huang428bafa2016-05-12 14:51:21 -04002368#define amdgpu_dpm_get_sclk_od(adev) \
2369 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2370
2371#define amdgpu_dpm_set_sclk_od(adev, value) \
2372 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2373
Eric Huangf2bdc052016-05-24 15:11:17 -04002374#define amdgpu_dpm_get_mclk_od(adev) \
2375 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2376
2377#define amdgpu_dpm_set_mclk_od(adev, value) \
2378 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2379
Jammy Zhoue61710c2015-11-10 18:31:08 -05002380#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002381 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002382
2383#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2384
2385/* Common functions */
2386int amdgpu_gpu_reset(struct amdgpu_device *adev);
Chunming Zhou3ad81f12016-08-05 17:30:17 +08002387bool amdgpu_need_backup(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002388void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2389bool amdgpu_card_posted(struct amdgpu_device *adev);
2390void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002391
Alex Deucher97b2e202015-04-20 16:51:00 -04002392int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2393int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2394 u32 ip_instance, u32 ring,
2395 struct amdgpu_ring **out_ring);
2396void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2397bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002398int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002399int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2400 uint32_t flags);
2401bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002402struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002403bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2404 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002405bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2406 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002407bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2408uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2409 struct ttm_mem_reg *mem);
2410void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2411void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2412void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002413u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2414int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002415void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2416 const u32 *registers,
2417 const u32 array_size);
2418
2419bool amdgpu_device_is_px(struct drm_device *dev);
2420/* atpx handler */
2421#if defined(CONFIG_VGA_SWITCHEROO)
2422void amdgpu_register_atpx_handler(void);
2423void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002424bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002425bool amdgpu_is_atpx_hybrid(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002426#else
2427static inline void amdgpu_register_atpx_handler(void) {}
2428static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002429static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002430static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002431#endif
2432
2433/*
2434 * KMS
2435 */
2436extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002437extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002438
2439int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2440int amdgpu_driver_unload_kms(struct drm_device *dev);
2441void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2442int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2443void amdgpu_driver_postclose_kms(struct drm_device *dev,
2444 struct drm_file *file_priv);
2445void amdgpu_driver_preclose_kms(struct drm_device *dev,
2446 struct drm_file *file_priv);
Alex Deucher810ddc32016-08-23 13:25:49 -04002447int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon);
2448int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002449u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2450int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2451void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2452int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002453 int *max_error,
2454 struct timeval *vblank_time,
2455 unsigned flags);
2456long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2457 unsigned long arg);
2458
2459/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002460 * functions used by amdgpu_encoder.c
2461 */
2462struct amdgpu_afmt_acr {
2463 u32 clock;
2464
2465 int n_32khz;
2466 int cts_32khz;
2467
2468 int n_44_1khz;
2469 int cts_44_1khz;
2470
2471 int n_48khz;
2472 int cts_48khz;
2473
2474};
2475
2476struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2477
2478/* amdgpu_acpi.c */
2479#if defined(CONFIG_ACPI)
2480int amdgpu_acpi_init(struct amdgpu_device *adev);
2481void amdgpu_acpi_fini(struct amdgpu_device *adev);
2482bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2483int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2484 u8 perf_req, bool advertise);
2485int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2486#else
2487static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2488static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2489#endif
2490
2491struct amdgpu_bo_va_mapping *
2492amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2493 uint64_t addr, struct amdgpu_bo **bo);
2494
2495#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002496#endif