blob: 06a7cab3bcc73d183b410c18569127cc67c1f328 [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;
67extern int amdgpu_benchmarking;
68extern int amdgpu_testing;
69extern int amdgpu_audio;
70extern int amdgpu_disp_priority;
71extern int amdgpu_hw_i2c;
72extern int amdgpu_pcie_gen2;
73extern int amdgpu_msi;
74extern int amdgpu_lockup_timeout;
75extern int amdgpu_dpm;
76extern int amdgpu_smc_load_fw;
77extern int amdgpu_aspm;
78extern int amdgpu_runtime_pm;
Alex Deucher97b2e202015-04-20 16:51:00 -040079extern unsigned amdgpu_ip_block_mask;
80extern int amdgpu_bapm;
81extern int amdgpu_deep_color;
82extern int amdgpu_vm_size;
83extern int amdgpu_vm_block_size;
Christian Königd9c13152015-09-28 12:31:26 +020084extern int amdgpu_vm_fault_stop;
Christian Königb495bd32015-09-10 14:00:35 +020085extern int amdgpu_vm_debug;
Jammy Zhou1333f722015-07-30 16:36:58 +080086extern int amdgpu_sched_jobs;
Jammy Zhou4afcb302015-07-30 16:44:05 +080087extern int amdgpu_sched_hw_submission;
Alex Deucher1f7371b2015-12-02 17:46:21 -050088extern int amdgpu_powerplay;
Huang Rui6bb6b292016-05-24 13:47:05 +080089extern int amdgpu_powercontainment;
Alex Deuchercd474ba2016-02-04 10:21:23 -050090extern unsigned amdgpu_pcie_gen_cap;
91extern unsigned amdgpu_pcie_lane_cap;
Nicolai Hähnle395d1fb2016-06-02 12:32:07 +020092extern unsigned amdgpu_cg_mask;
93extern unsigned amdgpu_pg_mask;
Nicolai Hähnle6f8941a2016-06-17 19:31:33 +020094extern char *amdgpu_disable_cu;
Rex Zhu66bc3f72016-07-28 17:36:35 +080095extern int amdgpu_sclk_deep_sleep_en;
Emily Deng9accf2f2016-08-10 16:01:25 +080096extern char *amdgpu_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -040097
Chunming Zhou4b559c92015-07-21 15:53:04 +080098#define AMDGPU_WAIT_IDLE_TIMEOUT_IN_MS 3000
Alex Deucher97b2e202015-04-20 16:51:00 -040099#define AMDGPU_MAX_USEC_TIMEOUT 100000 /* 100 ms */
100#define AMDGPU_FENCE_JIFFIES_TIMEOUT (HZ / 2)
101/* AMDGPU_IB_POOL_SIZE must be a power of 2 */
102#define AMDGPU_IB_POOL_SIZE 16
103#define AMDGPU_DEBUGFS_MAX_COMPONENTS 32
104#define AMDGPUFB_CONN_LIMIT 4
105#define AMDGPU_BIOS_NUM_SCRATCH 8
106
Alex Deucher97b2e202015-04-20 16:51:00 -0400107/* max number of rings */
108#define AMDGPU_MAX_RINGS 16
109#define AMDGPU_MAX_GFX_RINGS 1
110#define AMDGPU_MAX_COMPUTE_RINGS 8
111#define AMDGPU_MAX_VCE_RINGS 2
112
Jammy Zhou36f523a2015-09-01 12:54:27 +0800113/* max number of IP instances */
114#define AMDGPU_MAX_SDMA_INSTANCES 2
115
Alex Deucher97b2e202015-04-20 16:51:00 -0400116/* hardcode that limit for now */
117#define AMDGPU_VA_RESERVED_SIZE (8 << 20)
118
119/* hard reset data */
120#define AMDGPU_ASIC_RESET_DATA 0x39d5e86b
121
122/* reset flags */
123#define AMDGPU_RESET_GFX (1 << 0)
124#define AMDGPU_RESET_COMPUTE (1 << 1)
125#define AMDGPU_RESET_DMA (1 << 2)
126#define AMDGPU_RESET_CP (1 << 3)
127#define AMDGPU_RESET_GRBM (1 << 4)
128#define AMDGPU_RESET_DMA1 (1 << 5)
129#define AMDGPU_RESET_RLC (1 << 6)
130#define AMDGPU_RESET_SEM (1 << 7)
131#define AMDGPU_RESET_IH (1 << 8)
132#define AMDGPU_RESET_VMC (1 << 9)
133#define AMDGPU_RESET_MC (1 << 10)
134#define AMDGPU_RESET_DISPLAY (1 << 11)
135#define AMDGPU_RESET_UVD (1 << 12)
136#define AMDGPU_RESET_VCE (1 << 13)
137#define AMDGPU_RESET_VCE1 (1 << 14)
138
Alex Deucher97b2e202015-04-20 16:51:00 -0400139/* GFX current status */
140#define AMDGPU_GFX_NORMAL_MODE 0x00000000L
141#define AMDGPU_GFX_SAFE_MODE 0x00000001L
142#define AMDGPU_GFX_PG_DISABLED_MODE 0x00000002L
143#define AMDGPU_GFX_CG_DISABLED_MODE 0x00000004L
144#define AMDGPU_GFX_LBPW_DISABLED_MODE 0x00000008L
145
146/* max cursor sizes (in pixels) */
147#define CIK_CURSOR_WIDTH 128
148#define CIK_CURSOR_HEIGHT 128
149
150struct amdgpu_device;
Alex Deucher97b2e202015-04-20 16:51:00 -0400151struct amdgpu_ib;
152struct amdgpu_vm;
153struct amdgpu_ring;
Alex Deucher97b2e202015-04-20 16:51:00 -0400154struct amdgpu_cs_parser;
Chunming Zhoubb977d32015-08-18 15:16:40 +0800155struct amdgpu_job;
Alex Deucher97b2e202015-04-20 16:51:00 -0400156struct amdgpu_irq_src;
Alex Deucher0b492a42015-08-16 22:48:26 -0400157struct amdgpu_fpriv;
Alex Deucher97b2e202015-04-20 16:51:00 -0400158
159enum amdgpu_cp_irq {
160 AMDGPU_CP_IRQ_GFX_EOP = 0,
161 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE0_EOP,
162 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE1_EOP,
163 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE2_EOP,
164 AMDGPU_CP_IRQ_COMPUTE_MEC1_PIPE3_EOP,
165 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE0_EOP,
166 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE1_EOP,
167 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE2_EOP,
168 AMDGPU_CP_IRQ_COMPUTE_MEC2_PIPE3_EOP,
169
170 AMDGPU_CP_IRQ_LAST
171};
172
173enum amdgpu_sdma_irq {
174 AMDGPU_SDMA_IRQ_TRAP0 = 0,
175 AMDGPU_SDMA_IRQ_TRAP1,
176
177 AMDGPU_SDMA_IRQ_LAST
178};
179
180enum amdgpu_thermal_irq {
181 AMDGPU_THERMAL_IRQ_LOW_TO_HIGH = 0,
182 AMDGPU_THERMAL_IRQ_HIGH_TO_LOW,
183
184 AMDGPU_THERMAL_IRQ_LAST
185};
186
Alex Deucher97b2e202015-04-20 16:51:00 -0400187int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400188 enum amd_ip_block_type block_type,
189 enum amd_clockgating_state state);
Alex Deucher97b2e202015-04-20 16:51:00 -0400190int amdgpu_set_powergating_state(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400191 enum amd_ip_block_type block_type,
192 enum amd_powergating_state state);
Alex Deucher5dbbb602016-06-23 11:41:04 -0400193int amdgpu_wait_for_idle(struct amdgpu_device *adev,
194 enum amd_ip_block_type block_type);
195bool amdgpu_is_idle(struct amdgpu_device *adev,
196 enum amd_ip_block_type block_type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400197
198struct amdgpu_ip_block_version {
yanyang15fc3aee2015-05-22 14:39:35 -0400199 enum amd_ip_block_type type;
Alex Deucher97b2e202015-04-20 16:51:00 -0400200 u32 major;
201 u32 minor;
202 u32 rev;
yanyang15fc3aee2015-05-22 14:39:35 -0400203 const struct amd_ip_funcs *funcs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400204};
205
206int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400207 enum amd_ip_block_type type,
Alex Deucher97b2e202015-04-20 16:51:00 -0400208 u32 major, u32 minor);
209
210const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
211 struct amdgpu_device *adev,
yanyang15fc3aee2015-05-22 14:39:35 -0400212 enum amd_ip_block_type type);
Alex Deucher97b2e202015-04-20 16:51:00 -0400213
214/* provided by hw blocks that can move/clear data. e.g., gfx or sdma */
215struct amdgpu_buffer_funcs {
216 /* maximum bytes in a single operation */
217 uint32_t copy_max_bytes;
218
219 /* number of dw to reserve per operation */
220 unsigned copy_num_dw;
221
222 /* used for buffer migration */
Chunming Zhouc7ae72c2015-08-25 17:23:45 +0800223 void (*emit_copy_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400224 /* src addr in bytes */
225 uint64_t src_offset,
226 /* dst addr in bytes */
227 uint64_t dst_offset,
228 /* number of byte to transfer */
229 uint32_t byte_count);
230
231 /* maximum bytes in a single operation */
232 uint32_t fill_max_bytes;
233
234 /* number of dw to reserve per operation */
235 unsigned fill_num_dw;
236
237 /* used for buffer clearing */
Chunming Zhou6e7a3842015-08-27 13:46:09 +0800238 void (*emit_fill_buffer)(struct amdgpu_ib *ib,
Alex Deucher97b2e202015-04-20 16:51:00 -0400239 /* value to write to memory */
240 uint32_t src_data,
241 /* dst addr in bytes */
242 uint64_t dst_offset,
243 /* number of byte to fill */
244 uint32_t byte_count);
245};
246
247/* provided by hw blocks that can write ptes, e.g., sdma */
248struct amdgpu_vm_pte_funcs {
249 /* copy pte entries from GART */
250 void (*copy_pte)(struct amdgpu_ib *ib,
251 uint64_t pe, uint64_t src,
252 unsigned count);
253 /* write pte one entry at a time with addr mapping */
Christian Königde9ea7b2016-08-12 11:33:30 +0200254 void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe,
255 uint64_t value, unsigned count,
256 uint32_t incr);
Alex Deucher97b2e202015-04-20 16:51:00 -0400257 /* for linear pte/pde updates without addr mapping */
258 void (*set_pte_pde)(struct amdgpu_ib *ib,
259 uint64_t pe,
260 uint64_t addr, unsigned count,
261 uint32_t incr, uint32_t flags);
Alex Deucher97b2e202015-04-20 16:51:00 -0400262};
263
264/* provided by the gmc block */
265struct amdgpu_gart_funcs {
266 /* flush the vm tlb via mmio */
267 void (*flush_gpu_tlb)(struct amdgpu_device *adev,
268 uint32_t vmid);
269 /* write pte/pde updates using the cpu */
270 int (*set_pte_pde)(struct amdgpu_device *adev,
271 void *cpu_pt_addr, /* cpu addr of page table */
272 uint32_t gpu_page_idx, /* pte/pde to update */
273 uint64_t addr, /* addr to write into pte/pde */
274 uint32_t flags); /* access flags */
275};
276
277/* provided by the ih block */
278struct amdgpu_ih_funcs {
279 /* ring read/write ptr handling, called from interrupt context */
280 u32 (*get_wptr)(struct amdgpu_device *adev);
281 void (*decode_iv)(struct amdgpu_device *adev,
282 struct amdgpu_iv_entry *entry);
283 void (*set_rptr)(struct amdgpu_device *adev);
284};
285
286/* provided by hw blocks that expose a ring buffer for commands */
287struct amdgpu_ring_funcs {
288 /* ring read/write ptr handling */
289 u32 (*get_rptr)(struct amdgpu_ring *ring);
290 u32 (*get_wptr)(struct amdgpu_ring *ring);
291 void (*set_wptr)(struct amdgpu_ring *ring);
292 /* validating and patching of IBs */
293 int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
294 /* command emit functions */
295 void (*emit_ib)(struct amdgpu_ring *ring,
Christian Königd88bf582016-05-06 17:50:03 +0200296 struct amdgpu_ib *ib,
297 unsigned vm_id, bool ctx_switch);
Alex Deucher97b2e202015-04-20 16:51:00 -0400298 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
Chunming Zhou890ee232015-06-01 14:35:03 +0800299 uint64_t seq, unsigned flags);
Christian Königb8c7b392016-03-01 15:42:52 +0100300 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400301 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
302 uint64_t pd_addr);
Christian Königd2edb072015-05-11 14:10:34 +0200303 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
Chunming Zhou11afbde2016-03-03 11:38:48 +0800304 void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400305 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
306 uint32_t gds_base, uint32_t gds_size,
307 uint32_t gws_base, uint32_t gws_size,
308 uint32_t oa_base, uint32_t oa_size);
309 /* testing functions */
310 int (*test_ring)(struct amdgpu_ring *ring);
Christian Königbbec97a2016-07-05 21:07:17 +0200311 int (*test_ib)(struct amdgpu_ring *ring, long timeout);
Jammy Zhouedff0e22015-09-01 13:04:08 +0800312 /* insert NOP packets */
313 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +0100314 /* pad the indirect buffer to the necessary number of dw */
315 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Monk Liu03ccf482016-01-14 19:07:38 +0800316 unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
317 void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
Christian Königf06505b2016-07-20 13:49:34 +0200318 /* note usage for clock and power gating */
319 void (*begin_use)(struct amdgpu_ring *ring);
320 void (*end_use)(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400321};
322
323/*
324 * BIOS.
325 */
326bool amdgpu_get_bios(struct amdgpu_device *adev);
327bool amdgpu_read_bios(struct amdgpu_device *adev);
328
329/*
330 * Dummy page
331 */
332struct amdgpu_dummy_page {
333 struct page *page;
334 dma_addr_t addr;
335};
336int amdgpu_dummy_page_init(struct amdgpu_device *adev);
337void amdgpu_dummy_page_fini(struct amdgpu_device *adev);
338
339
340/*
341 * Clocks
342 */
343
344#define AMDGPU_MAX_PPLL 3
345
346struct amdgpu_clock {
347 struct amdgpu_pll ppll[AMDGPU_MAX_PPLL];
348 struct amdgpu_pll spll;
349 struct amdgpu_pll mpll;
350 /* 10 Khz units */
351 uint32_t default_mclk;
352 uint32_t default_sclk;
353 uint32_t default_dispclk;
354 uint32_t current_dispclk;
355 uint32_t dp_extclk;
356 uint32_t max_pixel_clock;
357};
358
359/*
360 * Fences.
361 */
362struct amdgpu_fence_driver {
Alex Deucher97b2e202015-04-20 16:51:00 -0400363 uint64_t gpu_addr;
364 volatile uint32_t *cpu_addr;
365 /* sync_seq is protected by ring emission lock */
Christian König742c0852016-03-14 15:46:06 +0100366 uint32_t sync_seq;
367 atomic_t last_seq;
Alex Deucher97b2e202015-04-20 16:51:00 -0400368 bool initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -0400369 struct amdgpu_irq_src *irq_src;
370 unsigned irq_type;
Christian Königc2776af2015-11-03 13:27:39 +0100371 struct timer_list fallback_timer;
Christian Königc89377d2016-03-13 19:19:48 +0100372 unsigned num_fences_mask;
Christian König4a7d74f2016-03-14 14:29:46 +0100373 spinlock_t lock;
Christian Königc89377d2016-03-13 19:19:48 +0100374 struct fence **fences;
Alex Deucher97b2e202015-04-20 16:51:00 -0400375};
376
377/* some special values for the owner field */
378#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
379#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
Alex Deucher97b2e202015-04-20 16:51:00 -0400380
Chunming Zhou890ee232015-06-01 14:35:03 +0800381#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
382#define AMDGPU_FENCE_FLAG_INT (1 << 1)
383
Alex Deucher97b2e202015-04-20 16:51:00 -0400384int amdgpu_fence_driver_init(struct amdgpu_device *adev);
385void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
386void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
387
Christian Könige6151a02016-03-15 14:52:26 +0100388int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
389 unsigned num_hw_submission);
Alex Deucher97b2e202015-04-20 16:51:00 -0400390int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
391 struct amdgpu_irq_src *irq_src,
392 unsigned irq_type);
Alex Deucher5ceb54c2015-08-05 12:41:48 -0400393void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
394void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
Christian König364beb22016-02-16 17:39:39 +0100395int amdgpu_fence_emit(struct amdgpu_ring *ring, struct fence **fence);
Alex Deucher97b2e202015-04-20 16:51:00 -0400396void amdgpu_fence_process(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -0400397int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
398unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
399
Alex Deucher97b2e202015-04-20 16:51:00 -0400400/*
Flora Cuic632d792016-08-02 11:32:41 +0800401 * BO.
Alex Deucher97b2e202015-04-20 16:51:00 -0400402 */
Christian König29b32592016-04-15 17:19:16 +0200403
Alex Deucher97b2e202015-04-20 16:51:00 -0400404struct amdgpu_bo_list_entry {
405 struct amdgpu_bo *robj;
406 struct ttm_validate_buffer tv;
407 struct amdgpu_bo_va *bo_va;
Alex Deucher97b2e202015-04-20 16:51:00 -0400408 uint32_t priority;
Christian König2f568db2016-02-23 12:36:59 +0100409 struct page **user_pages;
410 int user_invalidated;
Alex Deucher97b2e202015-04-20 16:51:00 -0400411};
412
413struct amdgpu_bo_va_mapping {
414 struct list_head list;
415 struct interval_tree_node it;
416 uint64_t offset;
417 uint32_t flags;
418};
419
420/* bo virtual addresses in a specific vm */
421struct amdgpu_bo_va {
422 /* protected by bo being reserved */
423 struct list_head bo_list;
Chunming Zhoubb1e38a42015-08-03 18:19:38 +0800424 struct fence *last_pt_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400425 unsigned ref_count;
426
Christian König7fc11952015-07-30 11:53:42 +0200427 /* protected by vm mutex and spinlock */
Alex Deucher97b2e202015-04-20 16:51:00 -0400428 struct list_head vm_status;
429
Christian König7fc11952015-07-30 11:53:42 +0200430 /* mappings for this bo_va */
431 struct list_head invalids;
432 struct list_head valids;
433
Alex Deucher97b2e202015-04-20 16:51:00 -0400434 /* constant after initialization */
435 struct amdgpu_vm *vm;
436 struct amdgpu_bo *bo;
437};
438
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800439#define AMDGPU_GEM_DOMAIN_MAX 0x3
440
Chunming Zhou478feaf2016-08-04 15:47:50 +0800441enum amdgpu_bo_shadow {
442 AMDGPU_BO_SHADOW_TO_NONE = 0,
443 AMDGPU_BO_SHADOW_TO_PARENT,
444 AMDGPU_BO_SHADOW_TO_SHADOW,
445};
446
Alex Deucher97b2e202015-04-20 16:51:00 -0400447struct amdgpu_bo {
448 /* Protected by gem.mutex */
449 struct list_head list;
450 /* Protected by tbo.reserved */
Christian König1ea863f2015-12-18 22:13:12 +0100451 u32 prefered_domains;
452 u32 allowed_domains;
Chunming Zhou7e5a5472015-04-24 17:37:30 +0800453 struct ttm_place placements[AMDGPU_GEM_DOMAIN_MAX + 1];
Alex Deucher97b2e202015-04-20 16:51:00 -0400454 struct ttm_placement placement;
455 struct ttm_buffer_object tbo;
456 struct ttm_bo_kmap_obj kmap;
457 u64 flags;
458 unsigned pin_count;
459 void *kptr;
460 u64 tiling_flags;
461 u64 metadata_flags;
462 void *metadata;
463 u32 metadata_size;
464 /* list of all virtual address to which this bo
465 * is associated to
466 */
467 struct list_head va;
468 /* Constant after initialization */
469 struct amdgpu_device *adev;
470 struct drm_gem_object gem_base;
Christian König82b9c552015-11-27 16:49:00 +0100471 struct amdgpu_bo *parent;
Chunming Zhoue7893c42016-07-26 14:13:21 +0800472 struct amdgpu_bo *shadow;
Chunming Zhou478feaf2016-08-04 15:47:50 +0800473 /* indicate if need to sync between bo and shadow */
474 enum amdgpu_bo_shadow backup_shadow;
Alex Deucher97b2e202015-04-20 16:51:00 -0400475
476 struct ttm_bo_kmap_obj dma_buf_vmap;
Alex Deucher97b2e202015-04-20 16:51:00 -0400477 struct amdgpu_mn *mn;
478 struct list_head mn_list;
479};
480#define gem_to_amdgpu_bo(gobj) container_of((gobj), struct amdgpu_bo, gem_base)
481
482void amdgpu_gem_object_free(struct drm_gem_object *obj);
483int amdgpu_gem_object_open(struct drm_gem_object *obj,
484 struct drm_file *file_priv);
485void amdgpu_gem_object_close(struct drm_gem_object *obj,
486 struct drm_file *file_priv);
487unsigned long amdgpu_gem_timeout(uint64_t timeout_ns);
488struct sg_table *amdgpu_gem_prime_get_sg_table(struct drm_gem_object *obj);
Christian König4d9c5142016-05-03 18:46:19 +0200489struct drm_gem_object *
490amdgpu_gem_prime_import_sg_table(struct drm_device *dev,
491 struct dma_buf_attachment *attach,
492 struct sg_table *sg);
Alex Deucher97b2e202015-04-20 16:51:00 -0400493struct dma_buf *amdgpu_gem_prime_export(struct drm_device *dev,
494 struct drm_gem_object *gobj,
495 int flags);
496int amdgpu_gem_prime_pin(struct drm_gem_object *obj);
497void amdgpu_gem_prime_unpin(struct drm_gem_object *obj);
498struct reservation_object *amdgpu_gem_prime_res_obj(struct drm_gem_object *);
499void *amdgpu_gem_prime_vmap(struct drm_gem_object *obj);
500void amdgpu_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
501int amdgpu_gem_debugfs_init(struct amdgpu_device *adev);
502
503/* sub-allocation manager, it has to be protected by another lock.
504 * By conception this is an helper for other part of the driver
505 * like the indirect buffer or semaphore, which both have their
506 * locking.
507 *
508 * Principe is simple, we keep a list of sub allocation in offset
509 * order (first entry has offset == 0, last entry has the highest
510 * offset).
511 *
512 * When allocating new object we first check if there is room at
513 * the end total_size - (last_object_offset + last_object_size) >=
514 * alloc_size. If so we allocate new object there.
515 *
516 * When there is not enough room at the end, we start waiting for
517 * each sub object until we reach object_offset+object_size >=
518 * alloc_size, this object then become the sub object we return.
519 *
520 * Alignment can't be bigger than page size.
521 *
522 * Hole are not considered for allocation to keep things simple.
523 * Assumption is that there won't be hole (all object on same
524 * alignment).
525 */
Christian König6ba60b82016-03-11 14:50:08 +0100526
527#define AMDGPU_SA_NUM_FENCE_LISTS 32
528
Alex Deucher97b2e202015-04-20 16:51:00 -0400529struct amdgpu_sa_manager {
530 wait_queue_head_t wq;
531 struct amdgpu_bo *bo;
532 struct list_head *hole;
Christian König6ba60b82016-03-11 14:50:08 +0100533 struct list_head flist[AMDGPU_SA_NUM_FENCE_LISTS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400534 struct list_head olist;
535 unsigned size;
536 uint64_t gpu_addr;
537 void *cpu_ptr;
538 uint32_t domain;
539 uint32_t align;
540};
541
Alex Deucher97b2e202015-04-20 16:51:00 -0400542/* sub-allocation buffer */
543struct amdgpu_sa_bo {
544 struct list_head olist;
545 struct list_head flist;
546 struct amdgpu_sa_manager *manager;
547 unsigned soffset;
548 unsigned eoffset;
Chunming Zhou4ce98912015-08-19 16:41:19 +0800549 struct fence *fence;
Alex Deucher97b2e202015-04-20 16:51:00 -0400550};
551
552/*
553 * GEM objects.
554 */
Christian König418aa0c2016-02-15 16:59:57 +0100555void amdgpu_gem_force_release(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -0400556int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
557 int alignment, u32 initial_domain,
558 u64 flags, bool kernel,
559 struct drm_gem_object **obj);
560
561int amdgpu_mode_dumb_create(struct drm_file *file_priv,
562 struct drm_device *dev,
563 struct drm_mode_create_dumb *args);
564int amdgpu_mode_dumb_mmap(struct drm_file *filp,
565 struct drm_device *dev,
566 uint32_t handle, uint64_t *offset_p);
Alex Deucher97b2e202015-04-20 16:51:00 -0400567/*
568 * Synchronization
569 */
570struct amdgpu_sync {
Christian Königf91b3a62015-08-20 14:47:40 +0800571 DECLARE_HASHTABLE(fences, 4);
Chunming Zhou3c623382015-08-20 18:33:59 +0800572 struct fence *last_vm_update;
Alex Deucher97b2e202015-04-20 16:51:00 -0400573};
574
575void amdgpu_sync_create(struct amdgpu_sync *sync);
Christian König91e1a522015-07-06 22:06:40 +0200576int amdgpu_sync_fence(struct amdgpu_device *adev, struct amdgpu_sync *sync,
577 struct fence *f);
Alex Deucher97b2e202015-04-20 16:51:00 -0400578int amdgpu_sync_resv(struct amdgpu_device *adev,
579 struct amdgpu_sync *sync,
580 struct reservation_object *resv,
581 void *owner);
Christian König1fbb2e92016-06-01 10:47:36 +0200582struct fence *amdgpu_sync_peek_fence(struct amdgpu_sync *sync,
583 struct amdgpu_ring *ring);
Christian Könige61235d2015-08-25 11:05:36 +0200584struct fence *amdgpu_sync_get_fence(struct amdgpu_sync *sync);
Christian König8a8f0b42016-02-03 15:11:39 +0100585void amdgpu_sync_free(struct amdgpu_sync *sync);
Christian König257bf152016-02-16 11:24:58 +0100586int amdgpu_sync_init(void);
587void amdgpu_sync_fini(void);
Rex Zhud573de22016-05-12 13:27:28 +0800588int amdgpu_fence_slab_init(void);
589void amdgpu_fence_slab_fini(void);
Alex Deucher97b2e202015-04-20 16:51:00 -0400590
591/*
592 * GART structures, functions & helpers
593 */
594struct amdgpu_mc;
595
596#define AMDGPU_GPU_PAGE_SIZE 4096
597#define AMDGPU_GPU_PAGE_MASK (AMDGPU_GPU_PAGE_SIZE - 1)
598#define AMDGPU_GPU_PAGE_SHIFT 12
599#define AMDGPU_GPU_PAGE_ALIGN(a) (((a) + AMDGPU_GPU_PAGE_MASK) & ~AMDGPU_GPU_PAGE_MASK)
600
601struct amdgpu_gart {
602 dma_addr_t table_addr;
603 struct amdgpu_bo *robj;
604 void *ptr;
605 unsigned num_gpu_pages;
606 unsigned num_cpu_pages;
607 unsigned table_size;
Christian Königa1d29472016-03-30 14:42:57 +0200608#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
Alex Deucher97b2e202015-04-20 16:51:00 -0400609 struct page **pages;
Christian Königa1d29472016-03-30 14:42:57 +0200610#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400611 bool ready;
612 const struct amdgpu_gart_funcs *gart_funcs;
613};
614
615int amdgpu_gart_table_ram_alloc(struct amdgpu_device *adev);
616void amdgpu_gart_table_ram_free(struct amdgpu_device *adev);
617int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev);
618void amdgpu_gart_table_vram_free(struct amdgpu_device *adev);
619int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev);
620void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev);
621int amdgpu_gart_init(struct amdgpu_device *adev);
622void amdgpu_gart_fini(struct amdgpu_device *adev);
623void amdgpu_gart_unbind(struct amdgpu_device *adev, unsigned offset,
624 int pages);
625int amdgpu_gart_bind(struct amdgpu_device *adev, unsigned offset,
626 int pages, struct page **pagelist,
627 dma_addr_t *dma_addr, uint32_t flags);
628
629/*
630 * GPU MC structures, functions & helpers
631 */
632struct amdgpu_mc {
633 resource_size_t aper_size;
634 resource_size_t aper_base;
635 resource_size_t agp_base;
636 /* for some chips with <= 32MB we need to lie
637 * about vram size near mc fb location */
638 u64 mc_vram_size;
639 u64 visible_vram_size;
640 u64 gtt_size;
641 u64 gtt_start;
642 u64 gtt_end;
643 u64 vram_start;
644 u64 vram_end;
645 unsigned vram_width;
646 u64 real_vram_size;
647 int vram_mtrr;
648 u64 gtt_base_align;
649 u64 mc_mask;
650 const struct firmware *fw; /* MC firmware */
651 uint32_t fw_version;
652 struct amdgpu_irq_src vm_fault;
Ken Wang81c59f52015-06-03 21:02:01 +0800653 uint32_t vram_type;
Chunming Zhou50b01972016-07-18 16:59:24 +0800654 uint32_t srbm_soft_reset;
655 struct amdgpu_mode_mc_save save;
Alex Deucher97b2e202015-04-20 16:51:00 -0400656};
657
658/*
659 * GPU doorbell structures, functions & helpers
660 */
661typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
662{
663 AMDGPU_DOORBELL_KIQ = 0x000,
664 AMDGPU_DOORBELL_HIQ = 0x001,
665 AMDGPU_DOORBELL_DIQ = 0x002,
666 AMDGPU_DOORBELL_MEC_RING0 = 0x010,
667 AMDGPU_DOORBELL_MEC_RING1 = 0x011,
668 AMDGPU_DOORBELL_MEC_RING2 = 0x012,
669 AMDGPU_DOORBELL_MEC_RING3 = 0x013,
670 AMDGPU_DOORBELL_MEC_RING4 = 0x014,
671 AMDGPU_DOORBELL_MEC_RING5 = 0x015,
672 AMDGPU_DOORBELL_MEC_RING6 = 0x016,
673 AMDGPU_DOORBELL_MEC_RING7 = 0x017,
674 AMDGPU_DOORBELL_GFX_RING0 = 0x020,
675 AMDGPU_DOORBELL_sDMA_ENGINE0 = 0x1E0,
676 AMDGPU_DOORBELL_sDMA_ENGINE1 = 0x1E1,
677 AMDGPU_DOORBELL_IH = 0x1E8,
678 AMDGPU_DOORBELL_MAX_ASSIGNMENT = 0x3FF,
679 AMDGPU_DOORBELL_INVALID = 0xFFFF
680} AMDGPU_DOORBELL_ASSIGNMENT;
681
682struct amdgpu_doorbell {
683 /* doorbell mmio */
684 resource_size_t base;
685 resource_size_t size;
686 u32 __iomem *ptr;
687 u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
688};
689
690void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
691 phys_addr_t *aperture_base,
692 size_t *aperture_size,
693 size_t *start_offset);
694
695/*
696 * IRQS.
697 */
698
699struct amdgpu_flip_work {
Michel Dänzer325cbba2016-08-04 12:39:37 +0900700 struct delayed_work flip_work;
Alex Deucher97b2e202015-04-20 16:51:00 -0400701 struct work_struct unpin_work;
702 struct amdgpu_device *adev;
703 int crtc_id;
Michel Dänzer325cbba2016-08-04 12:39:37 +0900704 u32 target_vblank;
Alex Deucher97b2e202015-04-20 16:51:00 -0400705 uint64_t base;
706 struct drm_pending_vblank_event *event;
707 struct amdgpu_bo *old_rbo;
Christian König1ffd2652015-08-11 17:29:52 +0200708 struct fence *excl;
709 unsigned shared_count;
710 struct fence **shared;
Christian Königc3874b72016-02-11 15:48:30 +0100711 struct fence_cb cb;
Alex Deuchercb9e59d2016-05-05 16:03:57 -0400712 bool async;
Alex Deucher97b2e202015-04-20 16:51:00 -0400713};
714
715
716/*
717 * CP & rings.
718 */
719
720struct amdgpu_ib {
721 struct amdgpu_sa_bo *sa_bo;
722 uint32_t length_dw;
723 uint64_t gpu_addr;
724 uint32_t *ptr;
Jammy Zhoude807f82015-05-11 23:41:41 +0800725 uint32_t flags;
Alex Deucher97b2e202015-04-20 16:51:00 -0400726};
727
728enum amdgpu_ring_type {
729 AMDGPU_RING_TYPE_GFX,
730 AMDGPU_RING_TYPE_COMPUTE,
731 AMDGPU_RING_TYPE_SDMA,
732 AMDGPU_RING_TYPE_UVD,
733 AMDGPU_RING_TYPE_VCE
734};
735
Nils Wallménius62250a92016-04-10 16:30:00 +0200736extern const struct amd_sched_backend_ops amdgpu_sched_ops;
Chunming Zhouc1b69ed2015-07-21 13:45:14 +0800737
Christian König50838c82016-02-03 13:44:52 +0100738int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs,
Monk Liuc5637832016-04-19 20:11:32 +0800739 struct amdgpu_job **job, struct amdgpu_vm *vm);
Christian Königd71518b2016-02-01 12:20:25 +0100740int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,
741 struct amdgpu_job **job);
Monk Liub6723c82016-03-10 12:14:44 +0800742
Christian Königa5fb4ec2016-06-29 15:10:31 +0200743void amdgpu_job_free_resources(struct amdgpu_job *job);
Christian König50838c82016-02-03 13:44:52 +0100744void amdgpu_job_free(struct amdgpu_job *job);
Christian Königd71518b2016-02-01 12:20:25 +0100745int amdgpu_job_submit(struct amdgpu_job *job, struct amdgpu_ring *ring,
Christian König2bd9ccf2016-02-01 12:53:58 +0100746 struct amd_sched_entity *entity, void *owner,
747 struct fence **f);
Chunming Zhou3c704e92015-07-29 10:33:14 +0800748
Alex Deucher97b2e202015-04-20 16:51:00 -0400749struct amdgpu_ring {
750 struct amdgpu_device *adev;
751 const struct amdgpu_ring_funcs *funcs;
752 struct amdgpu_fence_driver fence_drv;
Christian Königedf600d2016-05-03 15:54:54 +0200753 struct amd_gpu_scheduler sched;
Alex Deucher97b2e202015-04-20 16:51:00 -0400754
Alex Deucher97b2e202015-04-20 16:51:00 -0400755 struct amdgpu_bo *ring_obj;
756 volatile uint32_t *ring;
757 unsigned rptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400758 unsigned wptr;
759 unsigned wptr_old;
760 unsigned ring_size;
Christian Königc7e6be22016-01-21 13:06:05 +0100761 unsigned max_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400762 int count_dw;
Alex Deucher97b2e202015-04-20 16:51:00 -0400763 uint64_t gpu_addr;
764 uint32_t align_mask;
765 uint32_t ptr_mask;
766 bool ready;
767 u32 nop;
768 u32 idx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400769 u32 me;
770 u32 pipe;
771 u32 queue;
772 struct amdgpu_bo *mqd_obj;
773 u32 doorbell_index;
774 bool use_doorbell;
775 unsigned wptr_offs;
Alex Deucher97b2e202015-04-20 16:51:00 -0400776 unsigned fence_offs;
Christian Königaa3b73f2016-05-03 15:17:40 +0200777 uint64_t current_ctx;
Alex Deucher97b2e202015-04-20 16:51:00 -0400778 enum amdgpu_ring_type type;
779 char name[16];
Monk Liu128cff12016-01-14 18:08:16 +0800780 unsigned cond_exe_offs;
Christian König92c023c2016-07-19 14:34:17 +0200781 u64 cond_exe_gpu_addr;
782 volatile u32 *cond_exe_cpu_addr;
Monk Liua909c6b2016-06-14 12:02:21 -0400783#if defined(CONFIG_DEBUG_FS)
784 struct dentry *ent;
785#endif
Alex Deucher97b2e202015-04-20 16:51:00 -0400786};
787
788/*
789 * VM
790 */
791
792/* maximum number of VMIDs */
793#define AMDGPU_NUM_VM 16
794
Christian König96105e52016-08-12 12:59:59 +0200795/* Maximum number of PTEs the hardware can write with one command */
796#define AMDGPU_VM_MAX_UPDATE_SIZE 0x3FFFF
797
Alex Deucher97b2e202015-04-20 16:51:00 -0400798/* number of entries in page table */
799#define AMDGPU_VM_PTE_COUNT (1 << amdgpu_vm_block_size)
800
801/* PTBs (Page Table Blocks) need to be aligned to 32K */
802#define AMDGPU_VM_PTB_ALIGN_SIZE 32768
Alex Deucher97b2e202015-04-20 16:51:00 -0400803
Christian König1303c732016-08-03 17:46:42 +0200804/* LOG2 number of continuous pages for the fragment field */
805#define AMDGPU_LOG2_PAGES_PER_FRAG 4
806
Alex Deucher97b2e202015-04-20 16:51:00 -0400807#define AMDGPU_PTE_VALID (1 << 0)
808#define AMDGPU_PTE_SYSTEM (1 << 1)
809#define AMDGPU_PTE_SNOOPED (1 << 2)
810
811/* VI only */
812#define AMDGPU_PTE_EXECUTABLE (1 << 4)
813
814#define AMDGPU_PTE_READABLE (1 << 5)
815#define AMDGPU_PTE_WRITEABLE (1 << 6)
816
Christian König1303c732016-08-03 17:46:42 +0200817#define AMDGPU_PTE_FRAG(x) ((x & 0x1f) << 7)
Alex Deucher97b2e202015-04-20 16:51:00 -0400818
Christian Königd9c13152015-09-28 12:31:26 +0200819/* How to programm VM fault handling */
820#define AMDGPU_VM_FAULT_STOP_NEVER 0
821#define AMDGPU_VM_FAULT_STOP_FIRST 1
822#define AMDGPU_VM_FAULT_STOP_ALWAYS 2
823
Alex Deucher97b2e202015-04-20 16:51:00 -0400824struct amdgpu_vm_pt {
Christian Königee1782c2015-12-11 21:01:23 +0100825 struct amdgpu_bo_list_entry entry;
826 uint64_t addr;
Alex Deucher97b2e202015-04-20 16:51:00 -0400827};
828
Alex Deucher97b2e202015-04-20 16:51:00 -0400829struct amdgpu_vm {
Christian König25cfc3c2015-12-19 19:42:05 +0100830 /* tree of virtual addresses mapped */
Alex Deucher97b2e202015-04-20 16:51:00 -0400831 struct rb_root va;
832
Christian König7fc11952015-07-30 11:53:42 +0200833 /* protecting invalidated */
Alex Deucher97b2e202015-04-20 16:51:00 -0400834 spinlock_t status_lock;
835
836 /* BOs moved, but not yet updated in the PT */
837 struct list_head invalidated;
838
Christian König7fc11952015-07-30 11:53:42 +0200839 /* BOs cleared in the PT because of a move */
840 struct list_head cleared;
841
842 /* BO mappings freed, but not yet updated in the PT */
Alex Deucher97b2e202015-04-20 16:51:00 -0400843 struct list_head freed;
844
845 /* contains the page directory */
846 struct amdgpu_bo *page_directory;
847 unsigned max_pde_used;
Bas Nieuwenhuizen05906de2015-08-14 20:08:40 +0200848 struct fence *page_directory_fence;
Christian König5a712a82016-06-21 16:28:15 +0200849 uint64_t last_eviction_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400850
851 /* array of page tables, one for each page directory entry */
852 struct amdgpu_vm_pt *page_tables;
853
854 /* for id and flush management per ring */
Christian Königbcb1ba32016-03-08 15:40:11 +0100855 struct amdgpu_vm_id *ids[AMDGPU_MAX_RINGS];
Christian König25cfc3c2015-12-19 19:42:05 +0100856
jimqu81d75a32015-12-04 17:17:00 +0800857 /* protecting freed */
858 spinlock_t freed_lock;
Christian König2bd9ccf2016-02-01 12:53:58 +0100859
860 /* Scheduler entity for page table updates */
861 struct amd_sched_entity entity;
Chunming Zhou031e2982016-04-25 10:19:13 +0800862
863 /* client id */
864 u64 client_id;
Alex Deucher97b2e202015-04-20 16:51:00 -0400865};
866
Christian Königbcb1ba32016-03-08 15:40:11 +0100867struct amdgpu_vm_id {
Christian Königa9a78b32016-01-21 10:19:11 +0100868 struct list_head list;
Christian König832a9022016-02-15 12:33:02 +0100869 struct fence *first;
870 struct amdgpu_sync active;
Christian König41d9eb22016-03-01 16:46:18 +0100871 struct fence *last_flush;
Christian König0ea54b92016-05-04 10:20:01 +0200872 atomic64_t owner;
Christian König971fe9a92016-03-01 15:09:25 +0100873
Christian Königbcb1ba32016-03-08 15:40:11 +0100874 uint64_t pd_gpu_addr;
875 /* last flushed PD/PT update */
876 struct fence *flushed_updates;
877
Chunming Zhou6adb0512016-06-27 17:06:01 +0800878 uint32_t current_gpu_reset_count;
879
Christian König971fe9a92016-03-01 15:09:25 +0100880 uint32_t gds_base;
881 uint32_t gds_size;
882 uint32_t gws_base;
883 uint32_t gws_size;
884 uint32_t oa_base;
885 uint32_t oa_size;
Christian Königa9a78b32016-01-21 10:19:11 +0100886};
Christian König8d0a7ce2015-11-03 20:58:50 +0100887
Christian Königa9a78b32016-01-21 10:19:11 +0100888struct amdgpu_vm_manager {
889 /* Handling of VMIDs */
890 struct mutex lock;
891 unsigned num_ids;
892 struct list_head ids_lru;
Christian Königbcb1ba32016-03-08 15:40:11 +0100893 struct amdgpu_vm_id ids[AMDGPU_NUM_VM];
Christian König1c16c0a2015-11-14 21:31:40 +0100894
Christian König1fbb2e92016-06-01 10:47:36 +0200895 /* Handling of VM fences */
896 u64 fence_context;
897 unsigned seqno[AMDGPU_MAX_RINGS];
898
Christian König8b4fb002015-11-15 16:04:16 +0100899 uint32_t max_pfn;
Alex Deucher97b2e202015-04-20 16:51:00 -0400900 /* vram base address for page table entry */
Christian König8b4fb002015-11-15 16:04:16 +0100901 u64 vram_base_offset;
Alex Deucher97b2e202015-04-20 16:51:00 -0400902 /* is vm enabled? */
Christian König8b4fb002015-11-15 16:04:16 +0100903 bool enabled;
Alex Deucher97b2e202015-04-20 16:51:00 -0400904 /* vm pte handling */
905 const struct amdgpu_vm_pte_funcs *vm_pte_funcs;
Christian König2d55e452016-02-08 17:37:38 +0100906 struct amdgpu_ring *vm_pte_rings[AMDGPU_MAX_RINGS];
907 unsigned vm_pte_num_rings;
908 atomic_t vm_pte_next_ring;
Chunming Zhou031e2982016-04-25 10:19:13 +0800909 /* client id counter */
910 atomic64_t client_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -0400911};
912
Christian Königa9a78b32016-01-21 10:19:11 +0100913void amdgpu_vm_manager_init(struct amdgpu_device *adev);
Christian Königea89f8c2015-11-15 20:52:06 +0100914void amdgpu_vm_manager_fini(struct amdgpu_device *adev);
Christian König8b4fb002015-11-15 16:04:16 +0100915int amdgpu_vm_init(struct amdgpu_device *adev, struct amdgpu_vm *vm);
916void amdgpu_vm_fini(struct amdgpu_device *adev, struct amdgpu_vm *vm);
Christian König56467eb2015-12-11 15:16:32 +0100917void amdgpu_vm_get_pd_bo(struct amdgpu_vm *vm,
918 struct list_head *validated,
919 struct amdgpu_bo_list_entry *entry);
Christian König5a712a82016-06-21 16:28:15 +0200920void amdgpu_vm_get_pt_bos(struct amdgpu_device *adev, struct amdgpu_vm *vm,
921 struct list_head *duplicates);
Christian Königeceb8a12016-01-11 15:35:21 +0100922void amdgpu_vm_move_pt_bos_in_lru(struct amdgpu_device *adev,
923 struct amdgpu_vm *vm);
Christian König8b4fb002015-11-15 16:04:16 +0100924int amdgpu_vm_grab_id(struct amdgpu_vm *vm, struct amdgpu_ring *ring,
Christian König4ff37a82016-02-26 16:18:26 +0100925 struct amdgpu_sync *sync, struct fence *fence,
Chunming Zhoufd53be32016-07-01 17:59:01 +0800926 struct amdgpu_job *job);
927int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job);
Christian König971fe9a92016-03-01 15:09:25 +0100928void amdgpu_vm_reset_id(struct amdgpu_device *adev, unsigned vm_id);
Christian König8b4fb002015-11-15 16:04:16 +0100929int amdgpu_vm_update_page_directory(struct amdgpu_device *adev,
930 struct amdgpu_vm *vm);
931int amdgpu_vm_clear_freed(struct amdgpu_device *adev,
932 struct amdgpu_vm *vm);
933int amdgpu_vm_clear_invalids(struct amdgpu_device *adev, struct amdgpu_vm *vm,
934 struct amdgpu_sync *sync);
935int amdgpu_vm_bo_update(struct amdgpu_device *adev,
936 struct amdgpu_bo_va *bo_va,
937 struct ttm_mem_reg *mem);
938void amdgpu_vm_bo_invalidate(struct amdgpu_device *adev,
939 struct amdgpu_bo *bo);
940struct amdgpu_bo_va *amdgpu_vm_bo_find(struct amdgpu_vm *vm,
941 struct amdgpu_bo *bo);
942struct amdgpu_bo_va *amdgpu_vm_bo_add(struct amdgpu_device *adev,
943 struct amdgpu_vm *vm,
944 struct amdgpu_bo *bo);
945int amdgpu_vm_bo_map(struct amdgpu_device *adev,
946 struct amdgpu_bo_va *bo_va,
947 uint64_t addr, uint64_t offset,
948 uint64_t size, uint32_t flags);
949int amdgpu_vm_bo_unmap(struct amdgpu_device *adev,
950 struct amdgpu_bo_va *bo_va,
951 uint64_t addr);
952void amdgpu_vm_bo_rmv(struct amdgpu_device *adev,
953 struct amdgpu_bo_va *bo_va);
Christian König8b4fb002015-11-15 16:04:16 +0100954
Alex Deucher97b2e202015-04-20 16:51:00 -0400955/*
956 * context related structures
957 */
958
Christian König21c16bf2015-07-07 17:24:49 +0200959struct amdgpu_ctx_ring {
Christian König91404fb2015-08-05 18:33:21 +0200960 uint64_t sequence;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800961 struct fence **fences;
Christian König91404fb2015-08-05 18:33:21 +0200962 struct amd_sched_entity entity;
Christian König21c16bf2015-07-07 17:24:49 +0200963};
964
Alex Deucher97b2e202015-04-20 16:51:00 -0400965struct amdgpu_ctx {
Alex Deucher0b492a42015-08-16 22:48:26 -0400966 struct kref refcount;
Chunming Zhou9cb7e5a2015-07-21 13:17:19 +0800967 struct amdgpu_device *adev;
Alex Deucher0b492a42015-08-16 22:48:26 -0400968 unsigned reset_counter;
Christian König21c16bf2015-07-07 17:24:49 +0200969 spinlock_t ring_lock;
Chunming Zhou37cd0ca2015-12-10 15:45:11 +0800970 struct fence **fences;
Christian König21c16bf2015-07-07 17:24:49 +0200971 struct amdgpu_ctx_ring rings[AMDGPU_MAX_RINGS];
Alex Deucher97b2e202015-04-20 16:51:00 -0400972};
973
974struct amdgpu_ctx_mgr {
Alex Deucher0b492a42015-08-16 22:48:26 -0400975 struct amdgpu_device *adev;
976 struct mutex lock;
977 /* protected by lock */
978 struct idr ctx_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -0400979};
980
Alex Deucher0b492a42015-08-16 22:48:26 -0400981struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
982int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
983
Christian König21c16bf2015-07-07 17:24:49 +0200984uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx, struct amdgpu_ring *ring,
Christian Königce882e62015-08-19 15:00:55 +0200985 struct fence *fence);
Christian König21c16bf2015-07-07 17:24:49 +0200986struct fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
987 struct amdgpu_ring *ring, uint64_t seq);
988
Alex Deucher0b492a42015-08-16 22:48:26 -0400989int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
990 struct drm_file *filp);
991
Christian Königefd4ccb2015-08-04 16:20:31 +0200992void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr);
993void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
Alex Deucher0b492a42015-08-16 22:48:26 -0400994
Alex Deucher97b2e202015-04-20 16:51:00 -0400995/*
996 * file private structure
997 */
998
999struct amdgpu_fpriv {
1000 struct amdgpu_vm vm;
1001 struct mutex bo_list_lock;
1002 struct idr bo_list_handles;
Alex Deucher0b492a42015-08-16 22:48:26 -04001003 struct amdgpu_ctx_mgr ctx_mgr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001004};
1005
1006/*
1007 * residency list
1008 */
1009
1010struct amdgpu_bo_list {
1011 struct mutex lock;
1012 struct amdgpu_bo *gds_obj;
1013 struct amdgpu_bo *gws_obj;
1014 struct amdgpu_bo *oa_obj;
Christian König211dff52016-02-22 15:40:59 +01001015 unsigned first_userptr;
Alex Deucher97b2e202015-04-20 16:51:00 -04001016 unsigned num_entries;
1017 struct amdgpu_bo_list_entry *array;
1018};
1019
1020struct amdgpu_bo_list *
1021amdgpu_bo_list_get(struct amdgpu_fpriv *fpriv, int id);
Christian König636ce252015-12-18 21:26:47 +01001022void amdgpu_bo_list_get_list(struct amdgpu_bo_list *list,
1023 struct list_head *validated);
Alex Deucher97b2e202015-04-20 16:51:00 -04001024void amdgpu_bo_list_put(struct amdgpu_bo_list *list);
1025void amdgpu_bo_list_free(struct amdgpu_bo_list *list);
1026
1027/*
1028 * GFX stuff
1029 */
1030#include "clearstate_defs.h"
1031
Alex Deucher79e54122016-04-08 15:45:13 -04001032struct amdgpu_rlc_funcs {
1033 void (*enter_safe_mode)(struct amdgpu_device *adev);
1034 void (*exit_safe_mode)(struct amdgpu_device *adev);
1035};
1036
Alex Deucher97b2e202015-04-20 16:51:00 -04001037struct amdgpu_rlc {
1038 /* for power gating */
1039 struct amdgpu_bo *save_restore_obj;
1040 uint64_t save_restore_gpu_addr;
1041 volatile uint32_t *sr_ptr;
1042 const u32 *reg_list;
1043 u32 reg_list_size;
1044 /* for clear state */
1045 struct amdgpu_bo *clear_state_obj;
1046 uint64_t clear_state_gpu_addr;
1047 volatile uint32_t *cs_ptr;
1048 const struct cs_section_def *cs_data;
1049 u32 clear_state_size;
1050 /* for cp tables */
1051 struct amdgpu_bo *cp_table_obj;
1052 uint64_t cp_table_gpu_addr;
1053 volatile uint32_t *cp_table_ptr;
1054 u32 cp_table_size;
Alex Deucher79e54122016-04-08 15:45:13 -04001055
1056 /* safe mode for updating CG/PG state */
1057 bool in_safe_mode;
1058 const struct amdgpu_rlc_funcs *funcs;
Eric Huang2b6cd972016-04-14 17:26:07 -04001059
1060 /* for firmware data */
1061 u32 save_and_restore_offset;
1062 u32 clear_state_descriptor_offset;
1063 u32 avail_scratch_ram_locations;
1064 u32 reg_restore_list_size;
1065 u32 reg_list_format_start;
1066 u32 reg_list_format_separate_start;
1067 u32 starting_offsets_start;
1068 u32 reg_list_format_size_bytes;
1069 u32 reg_list_size_bytes;
1070
1071 u32 *register_list_format;
1072 u32 *register_restore;
Alex Deucher97b2e202015-04-20 16:51:00 -04001073};
1074
1075struct amdgpu_mec {
1076 struct amdgpu_bo *hpd_eop_obj;
1077 u64 hpd_eop_gpu_addr;
1078 u32 num_pipe;
1079 u32 num_mec;
1080 u32 num_queue;
1081};
1082
1083/*
1084 * GPU scratch registers structures, functions & helpers
1085 */
1086struct amdgpu_scratch {
1087 unsigned num_reg;
1088 uint32_t reg_base;
1089 bool free[32];
1090 uint32_t reg[32];
1091};
1092
1093/*
1094 * GFX configurations
1095 */
1096struct amdgpu_gca_config {
1097 unsigned max_shader_engines;
1098 unsigned max_tile_pipes;
1099 unsigned max_cu_per_sh;
1100 unsigned max_sh_per_se;
1101 unsigned max_backends_per_se;
1102 unsigned max_texture_channel_caches;
1103 unsigned max_gprs;
1104 unsigned max_gs_threads;
1105 unsigned max_hw_contexts;
1106 unsigned sc_prim_fifo_size_frontend;
1107 unsigned sc_prim_fifo_size_backend;
1108 unsigned sc_hiz_tile_fifo_size;
1109 unsigned sc_earlyz_tile_fifo_size;
1110
1111 unsigned num_tile_pipes;
1112 unsigned backend_enable_mask;
1113 unsigned mem_max_burst_length_bytes;
1114 unsigned mem_row_size_in_kb;
1115 unsigned shader_engine_tile_size;
1116 unsigned num_gpus;
1117 unsigned multi_gpu_tile_size;
1118 unsigned mc_arb_ramcfg;
1119 unsigned gb_addr_config;
Alex Deucher8f8e00c2016-02-12 00:39:13 -05001120 unsigned num_rbs;
Alex Deucher97b2e202015-04-20 16:51:00 -04001121
1122 uint32_t tile_mode_array[32];
1123 uint32_t macrotile_mode_array[16];
1124};
1125
Alex Deucher7dae69a2016-05-03 16:25:53 -04001126struct amdgpu_cu_info {
1127 uint32_t number; /* total active CU number */
1128 uint32_t ao_cu_mask;
1129 uint32_t bitmap[4][4];
1130};
1131
Alex Deucherb95e31f2016-07-07 15:01:42 -04001132struct amdgpu_gfx_funcs {
1133 /* get the gpu clock counter */
1134 uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
Tom St Denis9559ef52016-06-28 10:26:48 -04001135 void (*select_se_sh)(struct amdgpu_device *adev, u32 se_num, u32 sh_num, u32 instance);
Alex Deucherb95e31f2016-07-07 15:01:42 -04001136};
1137
Alex Deucher97b2e202015-04-20 16:51:00 -04001138struct amdgpu_gfx {
1139 struct mutex gpu_clock_mutex;
1140 struct amdgpu_gca_config config;
1141 struct amdgpu_rlc rlc;
1142 struct amdgpu_mec mec;
1143 struct amdgpu_scratch scratch;
1144 const struct firmware *me_fw; /* ME firmware */
1145 uint32_t me_fw_version;
1146 const struct firmware *pfp_fw; /* PFP firmware */
1147 uint32_t pfp_fw_version;
1148 const struct firmware *ce_fw; /* CE firmware */
1149 uint32_t ce_fw_version;
1150 const struct firmware *rlc_fw; /* RLC firmware */
1151 uint32_t rlc_fw_version;
1152 const struct firmware *mec_fw; /* MEC firmware */
1153 uint32_t mec_fw_version;
1154 const struct firmware *mec2_fw; /* MEC2 firmware */
1155 uint32_t mec2_fw_version;
Ken Wang02558a02015-06-03 19:52:06 +08001156 uint32_t me_feature_version;
1157 uint32_t ce_feature_version;
1158 uint32_t pfp_feature_version;
Jammy Zhou351643d2015-08-04 10:43:50 +08001159 uint32_t rlc_feature_version;
1160 uint32_t mec_feature_version;
1161 uint32_t mec2_feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001162 struct amdgpu_ring gfx_ring[AMDGPU_MAX_GFX_RINGS];
1163 unsigned num_gfx_rings;
1164 struct amdgpu_ring compute_ring[AMDGPU_MAX_COMPUTE_RINGS];
1165 unsigned num_compute_rings;
1166 struct amdgpu_irq_src eop_irq;
1167 struct amdgpu_irq_src priv_reg_irq;
1168 struct amdgpu_irq_src priv_inst_irq;
1169 /* gfx status */
Alex Deucher7dae69a2016-05-03 16:25:53 -04001170 uint32_t gfx_current_status;
Ken Wanga101a892015-06-03 17:47:54 +08001171 /* ce ram size*/
Alex Deucher7dae69a2016-05-03 16:25:53 -04001172 unsigned ce_ram_size;
1173 struct amdgpu_cu_info cu_info;
Alex Deucherb95e31f2016-07-07 15:01:42 -04001174 const struct amdgpu_gfx_funcs *funcs;
Chunming Zhou3d7c6382016-07-15 11:28:30 +08001175
1176 /* reset mask */
1177 uint32_t grbm_soft_reset;
1178 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001179};
1180
Christian Königb07c60c2016-01-31 12:29:04 +01001181int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
Alex Deucher97b2e202015-04-20 16:51:00 -04001182 unsigned size, struct amdgpu_ib *ib);
Christian König4d9c5142016-05-03 18:46:19 +02001183void amdgpu_ib_free(struct amdgpu_device *adev, struct amdgpu_ib *ib,
1184 struct fence *f);
Christian Königb07c60c2016-01-31 12:29:04 +01001185int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
Christian König336d1f52016-02-16 10:57:10 +01001186 struct amdgpu_ib *ib, struct fence *last_vm_update,
Monk Liuc5637832016-04-19 20:11:32 +08001187 struct amdgpu_job *job, struct fence **f);
Alex Deucher97b2e202015-04-20 16:51:00 -04001188int amdgpu_ib_pool_init(struct amdgpu_device *adev);
1189void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
1190int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001191int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
Jammy Zhouedff0e22015-09-01 13:04:08 +08001192void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
Christian König9e5d53092016-01-31 12:20:55 +01001193void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
Alex Deucher97b2e202015-04-20 16:51:00 -04001194void amdgpu_ring_commit(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001195void amdgpu_ring_undo(struct amdgpu_ring *ring);
Alex Deucher97b2e202015-04-20 16:51:00 -04001196int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
1197 unsigned ring_size, u32 nop, u32 align_mask,
1198 struct amdgpu_irq_src *irq_src, unsigned irq_type,
1199 enum amdgpu_ring_type ring_type);
1200void amdgpu_ring_fini(struct amdgpu_ring *ring);
1201
1202/*
1203 * CS.
1204 */
1205struct amdgpu_cs_chunk {
1206 uint32_t chunk_id;
1207 uint32_t length_dw;
Christian König758ac172016-05-06 22:14:00 +02001208 void *kdata;
Alex Deucher97b2e202015-04-20 16:51:00 -04001209};
1210
1211struct amdgpu_cs_parser {
1212 struct amdgpu_device *adev;
1213 struct drm_file *filp;
Christian König3cb485f2015-05-11 15:34:59 +02001214 struct amdgpu_ctx *ctx;
Christian Königc3cca412015-12-15 14:41:33 +01001215
Alex Deucher97b2e202015-04-20 16:51:00 -04001216 /* chunks */
1217 unsigned nchunks;
1218 struct amdgpu_cs_chunk *chunks;
Alex Deucher97b2e202015-04-20 16:51:00 -04001219
Christian König50838c82016-02-03 13:44:52 +01001220 /* scheduler job object */
1221 struct amdgpu_job *job;
Alex Deucher97b2e202015-04-20 16:51:00 -04001222
Christian Königc3cca412015-12-15 14:41:33 +01001223 /* buffer objects */
1224 struct ww_acquire_ctx ticket;
1225 struct amdgpu_bo_list *bo_list;
1226 struct amdgpu_bo_list_entry vm_pd;
1227 struct list_head validated;
1228 struct fence *fence;
1229 uint64_t bytes_moved_threshold;
1230 uint64_t bytes_moved;
Alex Deucher97b2e202015-04-20 16:51:00 -04001231
1232 /* user fence */
Christian König91acbeb2015-12-14 16:42:31 +01001233 struct amdgpu_bo_list_entry uf_entry;
Alex Deucher97b2e202015-04-20 16:51:00 -04001234};
1235
Chunming Zhoubb977d32015-08-18 15:16:40 +08001236struct amdgpu_job {
1237 struct amd_sched_job base;
1238 struct amdgpu_device *adev;
Christian Königedf600d2016-05-03 15:54:54 +02001239 struct amdgpu_vm *vm;
Christian Königb07c60c2016-01-31 12:29:04 +01001240 struct amdgpu_ring *ring;
Christian Könige86f9ce2016-02-08 12:13:05 +01001241 struct amdgpu_sync sync;
Chunming Zhoubb977d32015-08-18 15:16:40 +08001242 struct amdgpu_ib *ibs;
Monk Liu73cfa5f2016-03-17 13:48:13 +08001243 struct fence *fence; /* the hw fence */
Chunming Zhoubb977d32015-08-18 15:16:40 +08001244 uint32_t num_ibs;
Christian Könige2840222015-11-05 19:49:48 +01001245 void *owner;
Christian König92f25092016-05-06 15:57:42 +02001246 uint64_t ctx;
Chunming Zhoufd53be32016-07-01 17:59:01 +08001247 bool vm_needs_flush;
Christian Königd88bf582016-05-06 17:50:03 +02001248 unsigned vm_id;
1249 uint64_t vm_pd_addr;
1250 uint32_t gds_base, gds_size;
1251 uint32_t gws_base, gws_size;
1252 uint32_t oa_base, oa_size;
Christian König758ac172016-05-06 22:14:00 +02001253
1254 /* user fence handling */
Christian Königb5f5acb2016-06-29 13:26:41 +02001255 uint64_t uf_addr;
Christian König758ac172016-05-06 22:14:00 +02001256 uint64_t uf_sequence;
1257
Chunming Zhoubb977d32015-08-18 15:16:40 +08001258};
Junwei Zhanga6db8a32015-09-09 09:21:19 +08001259#define to_amdgpu_job(sched_job) \
1260 container_of((sched_job), struct amdgpu_job, base)
Chunming Zhoubb977d32015-08-18 15:16:40 +08001261
Christian König7270f832016-01-31 11:00:41 +01001262static inline u32 amdgpu_get_ib_value(struct amdgpu_cs_parser *p,
1263 uint32_t ib_idx, int idx)
Alex Deucher97b2e202015-04-20 16:51:00 -04001264{
Christian König50838c82016-02-03 13:44:52 +01001265 return p->job->ibs[ib_idx].ptr[idx];
Alex Deucher97b2e202015-04-20 16:51:00 -04001266}
1267
Christian König7270f832016-01-31 11:00:41 +01001268static inline void amdgpu_set_ib_value(struct amdgpu_cs_parser *p,
1269 uint32_t ib_idx, int idx,
1270 uint32_t value)
1271{
Christian König50838c82016-02-03 13:44:52 +01001272 p->job->ibs[ib_idx].ptr[idx] = value;
Christian König7270f832016-01-31 11:00:41 +01001273}
1274
Alex Deucher97b2e202015-04-20 16:51:00 -04001275/*
1276 * Writeback
1277 */
1278#define AMDGPU_MAX_WB 1024 /* Reserve at most 1024 WB slots for amdgpu-owned rings. */
1279
1280struct amdgpu_wb {
1281 struct amdgpu_bo *wb_obj;
1282 volatile uint32_t *wb;
1283 uint64_t gpu_addr;
1284 u32 num_wb; /* Number of wb slots actually reserved for amdgpu. */
1285 unsigned long used[DIV_ROUND_UP(AMDGPU_MAX_WB, BITS_PER_LONG)];
1286};
1287
1288int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb);
1289void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb);
1290
Alex Deucher97b2e202015-04-20 16:51:00 -04001291
Alex Deucher97b2e202015-04-20 16:51:00 -04001292
1293enum amdgpu_int_thermal_type {
1294 THERMAL_TYPE_NONE,
1295 THERMAL_TYPE_EXTERNAL,
1296 THERMAL_TYPE_EXTERNAL_GPIO,
1297 THERMAL_TYPE_RV6XX,
1298 THERMAL_TYPE_RV770,
1299 THERMAL_TYPE_ADT7473_WITH_INTERNAL,
1300 THERMAL_TYPE_EVERGREEN,
1301 THERMAL_TYPE_SUMO,
1302 THERMAL_TYPE_NI,
1303 THERMAL_TYPE_SI,
1304 THERMAL_TYPE_EMC2103_WITH_INTERNAL,
1305 THERMAL_TYPE_CI,
1306 THERMAL_TYPE_KV,
1307};
1308
1309enum amdgpu_dpm_auto_throttle_src {
1310 AMDGPU_DPM_AUTO_THROTTLE_SRC_THERMAL,
1311 AMDGPU_DPM_AUTO_THROTTLE_SRC_EXTERNAL
1312};
1313
1314enum amdgpu_dpm_event_src {
1315 AMDGPU_DPM_EVENT_SRC_ANALOG = 0,
1316 AMDGPU_DPM_EVENT_SRC_EXTERNAL = 1,
1317 AMDGPU_DPM_EVENT_SRC_DIGITAL = 2,
1318 AMDGPU_DPM_EVENT_SRC_ANALOG_OR_EXTERNAL = 3,
1319 AMDGPU_DPM_EVENT_SRC_DIGIAL_OR_EXTERNAL = 4
1320};
1321
1322#define AMDGPU_MAX_VCE_LEVELS 6
1323
1324enum amdgpu_vce_level {
1325 AMDGPU_VCE_LEVEL_AC_ALL = 0, /* AC, All cases */
1326 AMDGPU_VCE_LEVEL_DC_EE = 1, /* DC, entropy encoding */
1327 AMDGPU_VCE_LEVEL_DC_LL_LOW = 2, /* DC, low latency queue, res <= 720 */
1328 AMDGPU_VCE_LEVEL_DC_LL_HIGH = 3, /* DC, low latency queue, 1080 >= res > 720 */
1329 AMDGPU_VCE_LEVEL_DC_GP_LOW = 4, /* DC, general purpose queue, res <= 720 */
1330 AMDGPU_VCE_LEVEL_DC_GP_HIGH = 5, /* DC, general purpose queue, 1080 >= res > 720 */
1331};
1332
1333struct amdgpu_ps {
1334 u32 caps; /* vbios flags */
1335 u32 class; /* vbios flags */
1336 u32 class2; /* vbios flags */
1337 /* UVD clocks */
1338 u32 vclk;
1339 u32 dclk;
1340 /* VCE clocks */
1341 u32 evclk;
1342 u32 ecclk;
1343 bool vce_active;
1344 enum amdgpu_vce_level vce_level;
1345 /* asic priv */
1346 void *ps_priv;
1347};
1348
1349struct amdgpu_dpm_thermal {
1350 /* thermal interrupt work */
1351 struct work_struct work;
1352 /* low temperature threshold */
1353 int min_temp;
1354 /* high temperature threshold */
1355 int max_temp;
1356 /* was last interrupt low to high or high to low */
1357 bool high_to_low;
1358 /* interrupt source */
1359 struct amdgpu_irq_src irq;
1360};
1361
1362enum amdgpu_clk_action
1363{
1364 AMDGPU_SCLK_UP = 1,
1365 AMDGPU_SCLK_DOWN
1366};
1367
1368struct amdgpu_blacklist_clocks
1369{
1370 u32 sclk;
1371 u32 mclk;
1372 enum amdgpu_clk_action action;
1373};
1374
1375struct amdgpu_clock_and_voltage_limits {
1376 u32 sclk;
1377 u32 mclk;
1378 u16 vddc;
1379 u16 vddci;
1380};
1381
1382struct amdgpu_clock_array {
1383 u32 count;
1384 u32 *values;
1385};
1386
1387struct amdgpu_clock_voltage_dependency_entry {
1388 u32 clk;
1389 u16 v;
1390};
1391
1392struct amdgpu_clock_voltage_dependency_table {
1393 u32 count;
1394 struct amdgpu_clock_voltage_dependency_entry *entries;
1395};
1396
1397union amdgpu_cac_leakage_entry {
1398 struct {
1399 u16 vddc;
1400 u32 leakage;
1401 };
1402 struct {
1403 u16 vddc1;
1404 u16 vddc2;
1405 u16 vddc3;
1406 };
1407};
1408
1409struct amdgpu_cac_leakage_table {
1410 u32 count;
1411 union amdgpu_cac_leakage_entry *entries;
1412};
1413
1414struct amdgpu_phase_shedding_limits_entry {
1415 u16 voltage;
1416 u32 sclk;
1417 u32 mclk;
1418};
1419
1420struct amdgpu_phase_shedding_limits_table {
1421 u32 count;
1422 struct amdgpu_phase_shedding_limits_entry *entries;
1423};
1424
1425struct amdgpu_uvd_clock_voltage_dependency_entry {
1426 u32 vclk;
1427 u32 dclk;
1428 u16 v;
1429};
1430
1431struct amdgpu_uvd_clock_voltage_dependency_table {
1432 u8 count;
1433 struct amdgpu_uvd_clock_voltage_dependency_entry *entries;
1434};
1435
1436struct amdgpu_vce_clock_voltage_dependency_entry {
1437 u32 ecclk;
1438 u32 evclk;
1439 u16 v;
1440};
1441
1442struct amdgpu_vce_clock_voltage_dependency_table {
1443 u8 count;
1444 struct amdgpu_vce_clock_voltage_dependency_entry *entries;
1445};
1446
1447struct amdgpu_ppm_table {
1448 u8 ppm_design;
1449 u16 cpu_core_number;
1450 u32 platform_tdp;
1451 u32 small_ac_platform_tdp;
1452 u32 platform_tdc;
1453 u32 small_ac_platform_tdc;
1454 u32 apu_tdp;
1455 u32 dgpu_tdp;
1456 u32 dgpu_ulv_power;
1457 u32 tj_max;
1458};
1459
1460struct amdgpu_cac_tdp_table {
1461 u16 tdp;
1462 u16 configurable_tdp;
1463 u16 tdc;
1464 u16 battery_power_limit;
1465 u16 small_power_limit;
1466 u16 low_cac_leakage;
1467 u16 high_cac_leakage;
1468 u16 maximum_power_delivery_limit;
1469};
1470
1471struct amdgpu_dpm_dynamic_state {
1472 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_sclk;
1473 struct amdgpu_clock_voltage_dependency_table vddci_dependency_on_mclk;
1474 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_mclk;
1475 struct amdgpu_clock_voltage_dependency_table mvdd_dependency_on_mclk;
1476 struct amdgpu_clock_voltage_dependency_table vddc_dependency_on_dispclk;
1477 struct amdgpu_uvd_clock_voltage_dependency_table uvd_clock_voltage_dependency_table;
1478 struct amdgpu_vce_clock_voltage_dependency_table vce_clock_voltage_dependency_table;
1479 struct amdgpu_clock_voltage_dependency_table samu_clock_voltage_dependency_table;
1480 struct amdgpu_clock_voltage_dependency_table acp_clock_voltage_dependency_table;
1481 struct amdgpu_clock_voltage_dependency_table vddgfx_dependency_on_sclk;
1482 struct amdgpu_clock_array valid_sclk_values;
1483 struct amdgpu_clock_array valid_mclk_values;
1484 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_dc;
1485 struct amdgpu_clock_and_voltage_limits max_clock_voltage_on_ac;
1486 u32 mclk_sclk_ratio;
1487 u32 sclk_mclk_delta;
1488 u16 vddc_vddci_delta;
1489 u16 min_vddc_for_pcie_gen2;
1490 struct amdgpu_cac_leakage_table cac_leakage_table;
1491 struct amdgpu_phase_shedding_limits_table phase_shedding_limits_table;
1492 struct amdgpu_ppm_table *ppm_table;
1493 struct amdgpu_cac_tdp_table *cac_tdp_table;
1494};
1495
1496struct amdgpu_dpm_fan {
1497 u16 t_min;
1498 u16 t_med;
1499 u16 t_high;
1500 u16 pwm_min;
1501 u16 pwm_med;
1502 u16 pwm_high;
1503 u8 t_hyst;
1504 u32 cycle_delay;
1505 u16 t_max;
1506 u8 control_mode;
1507 u16 default_max_fan_pwm;
1508 u16 default_fan_output_sensitivity;
1509 u16 fan_output_sensitivity;
1510 bool ucode_fan_control;
1511};
1512
1513enum amdgpu_pcie_gen {
1514 AMDGPU_PCIE_GEN1 = 0,
1515 AMDGPU_PCIE_GEN2 = 1,
1516 AMDGPU_PCIE_GEN3 = 2,
1517 AMDGPU_PCIE_GEN_INVALID = 0xffff
1518};
1519
1520enum amdgpu_dpm_forced_level {
1521 AMDGPU_DPM_FORCED_LEVEL_AUTO = 0,
1522 AMDGPU_DPM_FORCED_LEVEL_LOW = 1,
1523 AMDGPU_DPM_FORCED_LEVEL_HIGH = 2,
Eric Huangf3898ea2015-12-11 16:24:34 -05001524 AMDGPU_DPM_FORCED_LEVEL_MANUAL = 3,
Alex Deucher97b2e202015-04-20 16:51:00 -04001525};
1526
1527struct amdgpu_vce_state {
1528 /* vce clocks */
1529 u32 evclk;
1530 u32 ecclk;
1531 /* gpu clocks */
1532 u32 sclk;
1533 u32 mclk;
1534 u8 clk_idx;
1535 u8 pstate;
1536};
1537
1538struct amdgpu_dpm_funcs {
1539 int (*get_temperature)(struct amdgpu_device *adev);
1540 int (*pre_set_power_state)(struct amdgpu_device *adev);
1541 int (*set_power_state)(struct amdgpu_device *adev);
1542 void (*post_set_power_state)(struct amdgpu_device *adev);
1543 void (*display_configuration_changed)(struct amdgpu_device *adev);
1544 u32 (*get_sclk)(struct amdgpu_device *adev, bool low);
1545 u32 (*get_mclk)(struct amdgpu_device *adev, bool low);
1546 void (*print_power_state)(struct amdgpu_device *adev, struct amdgpu_ps *ps);
1547 void (*debugfs_print_current_performance_level)(struct amdgpu_device *adev, struct seq_file *m);
1548 int (*force_performance_level)(struct amdgpu_device *adev, enum amdgpu_dpm_forced_level level);
1549 bool (*vblank_too_short)(struct amdgpu_device *adev);
1550 void (*powergate_uvd)(struct amdgpu_device *adev, bool gate);
Sonny Jiangb7a07762015-05-28 15:47:53 -04001551 void (*powergate_vce)(struct amdgpu_device *adev, bool gate);
Alex Deucher97b2e202015-04-20 16:51:00 -04001552 void (*enable_bapm)(struct amdgpu_device *adev, bool enable);
1553 void (*set_fan_control_mode)(struct amdgpu_device *adev, u32 mode);
1554 u32 (*get_fan_control_mode)(struct amdgpu_device *adev);
1555 int (*set_fan_speed_percent)(struct amdgpu_device *adev, u32 speed);
1556 int (*get_fan_speed_percent)(struct amdgpu_device *adev, u32 *speed);
Eric Huangc85e2992016-05-19 15:41:25 -04001557 int (*force_clock_level)(struct amdgpu_device *adev, enum pp_clock_type type, uint32_t mask);
1558 int (*print_clock_levels)(struct amdgpu_device *adev, enum pp_clock_type type, char *buf);
Eric Huang8b2e5742016-05-19 15:46:10 -04001559 int (*get_sclk_od)(struct amdgpu_device *adev);
1560 int (*set_sclk_od)(struct amdgpu_device *adev, uint32_t value);
Eric Huangf2bdc052016-05-24 15:11:17 -04001561 int (*get_mclk_od)(struct amdgpu_device *adev);
1562 int (*set_mclk_od)(struct amdgpu_device *adev, uint32_t value);
Alex Deucher97b2e202015-04-20 16:51:00 -04001563};
1564
1565struct amdgpu_dpm {
1566 struct amdgpu_ps *ps;
1567 /* number of valid power states */
1568 int num_ps;
1569 /* current power state that is active */
1570 struct amdgpu_ps *current_ps;
1571 /* requested power state */
1572 struct amdgpu_ps *requested_ps;
1573 /* boot up power state */
1574 struct amdgpu_ps *boot_ps;
1575 /* default uvd power state */
1576 struct amdgpu_ps *uvd_ps;
1577 /* vce requirements */
1578 struct amdgpu_vce_state vce_states[AMDGPU_MAX_VCE_LEVELS];
1579 enum amdgpu_vce_level vce_level;
Rex Zhu3a2c7882015-08-25 15:57:43 +08001580 enum amd_pm_state_type state;
1581 enum amd_pm_state_type user_state;
Alex Deucher97b2e202015-04-20 16:51:00 -04001582 u32 platform_caps;
1583 u32 voltage_response_time;
1584 u32 backbias_response_time;
1585 void *priv;
1586 u32 new_active_crtcs;
1587 int new_active_crtc_count;
1588 u32 current_active_crtcs;
1589 int current_active_crtc_count;
1590 struct amdgpu_dpm_dynamic_state dyn_state;
1591 struct amdgpu_dpm_fan fan;
1592 u32 tdp_limit;
1593 u32 near_tdp_limit;
1594 u32 near_tdp_limit_adjusted;
1595 u32 sq_ramping_threshold;
1596 u32 cac_leakage;
1597 u16 tdp_od_limit;
1598 u32 tdp_adjustment;
1599 u16 load_line_slope;
1600 bool power_control;
1601 bool ac_power;
1602 /* special states active */
1603 bool thermal_active;
1604 bool uvd_active;
1605 bool vce_active;
1606 /* thermal handling */
1607 struct amdgpu_dpm_thermal thermal;
1608 /* forced levels */
1609 enum amdgpu_dpm_forced_level forced_level;
1610};
1611
1612struct amdgpu_pm {
1613 struct mutex mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001614 u32 current_sclk;
1615 u32 current_mclk;
1616 u32 default_sclk;
1617 u32 default_mclk;
1618 struct amdgpu_i2c_chan *i2c_bus;
1619 /* internal thermal controller on rv6xx+ */
1620 enum amdgpu_int_thermal_type int_thermal_type;
1621 struct device *int_hwmon_dev;
1622 /* fan control parameters */
1623 bool no_fan;
1624 u8 fan_pulses_per_revolution;
1625 u8 fan_min_rpm;
1626 u8 fan_max_rpm;
1627 /* dpm */
1628 bool dpm_enabled;
Alex Deucherc86f5ebf2015-10-23 10:45:14 -04001629 bool sysfs_initialized;
Alex Deucher97b2e202015-04-20 16:51:00 -04001630 struct amdgpu_dpm dpm;
1631 const struct firmware *fw; /* SMC firmware */
1632 uint32_t fw_version;
1633 const struct amdgpu_dpm_funcs *funcs;
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001634 uint32_t pcie_gen_mask;
1635 uint32_t pcie_mlw_mask;
Rex Zhu7fb72a12015-11-19 13:35:30 +08001636 struct amd_pp_display_configuration pm_display_cfg;/* set by DAL */
Alex Deucher97b2e202015-04-20 16:51:00 -04001637};
1638
Alex Deucherd0dd7f02015-11-11 19:45:06 -05001639void amdgpu_get_pcie_info(struct amdgpu_device *adev);
1640
Alex Deucher97b2e202015-04-20 16:51:00 -04001641/*
1642 * UVD
1643 */
Arindam Nathc0365542016-04-12 13:46:15 +02001644#define AMDGPU_DEFAULT_UVD_HANDLES 10
1645#define AMDGPU_MAX_UVD_HANDLES 40
1646#define AMDGPU_UVD_STACK_SIZE (200*1024)
1647#define AMDGPU_UVD_HEAP_SIZE (256*1024)
1648#define AMDGPU_UVD_SESSION_SIZE (50*1024)
1649#define AMDGPU_UVD_FIRMWARE_OFFSET 256
Alex Deucher97b2e202015-04-20 16:51:00 -04001650
1651struct amdgpu_uvd {
1652 struct amdgpu_bo *vcpu_bo;
1653 void *cpu_addr;
1654 uint64_t gpu_addr;
Sonny Jiang562e2682016-04-18 16:05:04 -04001655 unsigned fw_version;
Leo Liu3f99dd82016-04-01 10:36:06 -04001656 void *saved_bo;
Arindam Nathc0365542016-04-12 13:46:15 +02001657 unsigned max_handles;
Alex Deucher97b2e202015-04-20 16:51:00 -04001658 atomic_t handles[AMDGPU_MAX_UVD_HANDLES];
1659 struct drm_file *filp[AMDGPU_MAX_UVD_HANDLES];
1660 struct delayed_work idle_work;
1661 const struct firmware *fw; /* UVD firmware */
1662 struct amdgpu_ring ring;
1663 struct amdgpu_irq_src irq;
1664 bool address_64_bit;
Christian König4cb5877c2016-07-26 12:05:40 +02001665 bool use_ctx_buf;
Christian Königead833e2016-02-10 14:35:19 +01001666 struct amd_sched_entity entity;
Chunming Zhoufc0b3b92016-07-18 17:18:01 +08001667 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001668};
1669
1670/*
1671 * VCE
1672 */
1673#define AMDGPU_MAX_VCE_HANDLES 16
Alex Deucher97b2e202015-04-20 16:51:00 -04001674#define AMDGPU_VCE_FIRMWARE_OFFSET 256
1675
Alex Deucher6a585772015-07-10 14:16:24 -04001676#define AMDGPU_VCE_HARVEST_VCE0 (1 << 0)
1677#define AMDGPU_VCE_HARVEST_VCE1 (1 << 1)
1678
Alex Deucher97b2e202015-04-20 16:51:00 -04001679struct amdgpu_vce {
1680 struct amdgpu_bo *vcpu_bo;
1681 uint64_t gpu_addr;
1682 unsigned fw_version;
1683 unsigned fb_version;
1684 atomic_t handles[AMDGPU_MAX_VCE_HANDLES];
1685 struct drm_file *filp[AMDGPU_MAX_VCE_HANDLES];
Christian Königf1689ec2015-06-11 20:56:18 +02001686 uint32_t img_size[AMDGPU_MAX_VCE_HANDLES];
Alex Deucher97b2e202015-04-20 16:51:00 -04001687 struct delayed_work idle_work;
Christian Königebff4852016-07-20 16:53:36 +02001688 struct mutex idle_mutex;
Alex Deucher97b2e202015-04-20 16:51:00 -04001689 const struct firmware *fw; /* VCE firmware */
1690 struct amdgpu_ring ring[AMDGPU_MAX_VCE_RINGS];
1691 struct amdgpu_irq_src irq;
Alex Deucher6a585772015-07-10 14:16:24 -04001692 unsigned harvest_config;
Christian Königc5949892016-02-10 17:43:00 +01001693 struct amd_sched_entity entity;
Chunming Zhou115933a2016-07-18 17:38:50 +08001694 uint32_t srbm_soft_reset;
Alex Deucher97b2e202015-04-20 16:51:00 -04001695};
1696
1697/*
1698 * SDMA
1699 */
Alex Deucherc113ea12015-10-08 16:30:37 -04001700struct amdgpu_sdma_instance {
Alex Deucher97b2e202015-04-20 16:51:00 -04001701 /* SDMA firmware */
1702 const struct firmware *fw;
1703 uint32_t fw_version;
Jammy Zhoucfa21042015-08-04 10:50:47 +08001704 uint32_t feature_version;
Alex Deucher97b2e202015-04-20 16:51:00 -04001705
1706 struct amdgpu_ring ring;
Jammy Zhou18111de2015-08-31 14:06:39 +08001707 bool burst_nop;
Alex Deucher97b2e202015-04-20 16:51:00 -04001708};
1709
Alex Deucherc113ea12015-10-08 16:30:37 -04001710struct amdgpu_sdma {
1711 struct amdgpu_sdma_instance instance[AMDGPU_MAX_SDMA_INSTANCES];
1712 struct amdgpu_irq_src trap_irq;
1713 struct amdgpu_irq_src illegal_inst_irq;
Christian Königedf600d2016-05-03 15:54:54 +02001714 int num_instances;
Chunming Zhoue702a682016-07-13 10:28:56 +08001715 uint32_t srbm_soft_reset;
Alex Deucherc113ea12015-10-08 16:30:37 -04001716};
1717
Alex Deucher97b2e202015-04-20 16:51:00 -04001718/*
1719 * Firmware
1720 */
1721struct amdgpu_firmware {
1722 struct amdgpu_firmware_info ucode[AMDGPU_UCODE_ID_MAXIMUM];
1723 bool smu_load;
1724 struct amdgpu_bo *fw_buf;
1725 unsigned int fw_size;
1726};
1727
1728/*
1729 * Benchmarking
1730 */
1731void amdgpu_benchmark(struct amdgpu_device *adev, int test_number);
1732
1733
1734/*
1735 * Testing
1736 */
1737void amdgpu_test_moves(struct amdgpu_device *adev);
1738void amdgpu_test_ring_sync(struct amdgpu_device *adev,
1739 struct amdgpu_ring *cpA,
1740 struct amdgpu_ring *cpB);
1741void amdgpu_test_syncing(struct amdgpu_device *adev);
1742
1743/*
1744 * MMU Notifier
1745 */
1746#if defined(CONFIG_MMU_NOTIFIER)
1747int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr);
1748void amdgpu_mn_unregister(struct amdgpu_bo *bo);
1749#else
Harry Wentland1d1106b2015-07-15 07:10:41 -04001750static inline int amdgpu_mn_register(struct amdgpu_bo *bo, unsigned long addr)
Alex Deucher97b2e202015-04-20 16:51:00 -04001751{
1752 return -ENODEV;
1753}
Harry Wentland1d1106b2015-07-15 07:10:41 -04001754static inline void amdgpu_mn_unregister(struct amdgpu_bo *bo) {}
Alex Deucher97b2e202015-04-20 16:51:00 -04001755#endif
1756
1757/*
1758 * Debugfs
1759 */
1760struct amdgpu_debugfs {
Nils Wallménius06ab6832016-05-02 12:46:15 -04001761 const struct drm_info_list *files;
Alex Deucher97b2e202015-04-20 16:51:00 -04001762 unsigned num_files;
1763};
1764
1765int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
Nils Wallménius06ab6832016-05-02 12:46:15 -04001766 const struct drm_info_list *files,
Alex Deucher97b2e202015-04-20 16:51:00 -04001767 unsigned nfiles);
1768int amdgpu_debugfs_fence_init(struct amdgpu_device *adev);
1769
1770#if defined(CONFIG_DEBUG_FS)
1771int amdgpu_debugfs_init(struct drm_minor *minor);
1772void amdgpu_debugfs_cleanup(struct drm_minor *minor);
1773#endif
1774
Huang Rui50ab2532016-06-12 15:51:09 +08001775int amdgpu_debugfs_firmware_init(struct amdgpu_device *adev);
1776
Alex Deucher97b2e202015-04-20 16:51:00 -04001777/*
1778 * amdgpu smumgr functions
1779 */
1780struct amdgpu_smumgr_funcs {
1781 int (*check_fw_load_finish)(struct amdgpu_device *adev, uint32_t fwtype);
1782 int (*request_smu_load_fw)(struct amdgpu_device *adev);
1783 int (*request_smu_specific_fw)(struct amdgpu_device *adev, uint32_t fwtype);
1784};
1785
1786/*
1787 * amdgpu smumgr
1788 */
1789struct amdgpu_smumgr {
1790 struct amdgpu_bo *toc_buf;
1791 struct amdgpu_bo *smu_buf;
1792 /* asic priv smu data */
1793 void *priv;
1794 spinlock_t smu_lock;
1795 /* smumgr functions */
1796 const struct amdgpu_smumgr_funcs *smumgr_funcs;
1797 /* ucode loading complete flag */
1798 uint32_t fw_flags;
1799};
1800
1801/*
1802 * ASIC specific register table accessible by UMD
1803 */
1804struct amdgpu_allowed_register_entry {
1805 uint32_t reg_offset;
1806 bool untouched;
1807 bool grbm_indexed;
1808};
1809
Alex Deucher97b2e202015-04-20 16:51:00 -04001810/*
1811 * ASIC specific functions.
1812 */
1813struct amdgpu_asic_funcs {
1814 bool (*read_disabled_bios)(struct amdgpu_device *adev);
Alex Deucher7946b872015-11-24 10:14:28 -05001815 bool (*read_bios_from_rom)(struct amdgpu_device *adev,
1816 u8 *bios, u32 length_bytes);
Alex Deucher97b2e202015-04-20 16:51:00 -04001817 int (*read_register)(struct amdgpu_device *adev, u32 se_num,
1818 u32 sh_num, u32 reg_offset, u32 *value);
1819 void (*set_vga_state)(struct amdgpu_device *adev, bool state);
1820 int (*reset)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001821 /* get the reference clock */
1822 u32 (*get_xclk)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001823 /* MM block clocks */
1824 int (*set_uvd_clocks)(struct amdgpu_device *adev, u32 vclk, u32 dclk);
1825 int (*set_vce_clocks)(struct amdgpu_device *adev, u32 evclk, u32 ecclk);
Andres Rodriguez048765a2016-06-11 02:51:32 -04001826 /* query virtual capabilities */
1827 u32 (*get_virtual_caps)(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04001828};
1829
1830/*
1831 * IOCTL.
1832 */
1833int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
1834 struct drm_file *filp);
1835int amdgpu_bo_list_ioctl(struct drm_device *dev, void *data,
1836 struct drm_file *filp);
1837
1838int amdgpu_gem_info_ioctl(struct drm_device *dev, void *data,
1839 struct drm_file *filp);
1840int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
1841 struct drm_file *filp);
1842int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
1843 struct drm_file *filp);
1844int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
1845 struct drm_file *filp);
1846int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
1847 struct drm_file *filp);
1848int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
1849 struct drm_file *filp);
1850int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1851int amdgpu_cs_wait_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
1852
1853int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
1854 struct drm_file *filp);
1855
1856/* VRAM scratch page for HDP bug, default vram page */
1857struct amdgpu_vram_scratch {
1858 struct amdgpu_bo *robj;
1859 volatile uint32_t *ptr;
1860 u64 gpu_addr;
1861};
1862
1863/*
1864 * ACPI
1865 */
1866struct amdgpu_atif_notification_cfg {
1867 bool enabled;
1868 int command_code;
1869};
1870
1871struct amdgpu_atif_notifications {
1872 bool display_switch;
1873 bool expansion_mode_change;
1874 bool thermal_state;
1875 bool forced_power_state;
1876 bool system_power_state;
1877 bool display_conf_change;
1878 bool px_gfx_switch;
1879 bool brightness_change;
1880 bool dgpu_display_event;
1881};
1882
1883struct amdgpu_atif_functions {
1884 bool system_params;
1885 bool sbios_requests;
1886 bool select_active_disp;
1887 bool lid_state;
1888 bool get_tv_standard;
1889 bool set_tv_standard;
1890 bool get_panel_expansion_mode;
1891 bool set_panel_expansion_mode;
1892 bool temperature_change;
1893 bool graphics_device_types;
1894};
1895
1896struct amdgpu_atif {
1897 struct amdgpu_atif_notifications notifications;
1898 struct amdgpu_atif_functions functions;
1899 struct amdgpu_atif_notification_cfg notification_cfg;
1900 struct amdgpu_encoder *encoder_for_bl;
1901};
1902
1903struct amdgpu_atcs_functions {
1904 bool get_ext_state;
1905 bool pcie_perf_req;
1906 bool pcie_dev_rdy;
1907 bool pcie_bus_width;
1908};
1909
1910struct amdgpu_atcs {
1911 struct amdgpu_atcs_functions functions;
1912};
1913
Alex Deucher97b2e202015-04-20 16:51:00 -04001914/*
Chunming Zhoud03846a2015-07-28 14:20:03 -04001915 * CGS
1916 */
Dave Airlie110e6f22016-04-12 13:25:48 +10001917struct cgs_device *amdgpu_cgs_create_device(struct amdgpu_device *adev);
1918void amdgpu_cgs_destroy_device(struct cgs_device *cgs_device);
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001919
1920
Alex Deucher7e471e62016-02-01 11:13:04 -05001921/* GPU virtualization */
Andres Rodriguez048765a2016-06-11 02:51:32 -04001922#define AMDGPU_VIRT_CAPS_SRIOV_EN (1 << 0)
1923#define AMDGPU_VIRT_CAPS_IS_VF (1 << 1)
Alex Deucher7e471e62016-02-01 11:13:04 -05001924struct amdgpu_virtualization {
1925 bool supports_sr_iov;
Andres Rodriguez048765a2016-06-11 02:51:32 -04001926 bool is_virtual;
1927 u32 caps;
Alex Deucher7e471e62016-02-01 11:13:04 -05001928};
1929
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001930/*
Alex Deucher97b2e202015-04-20 16:51:00 -04001931 * Core structure, functions and helpers.
1932 */
1933typedef uint32_t (*amdgpu_rreg_t)(struct amdgpu_device*, uint32_t);
1934typedef void (*amdgpu_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1935
1936typedef uint32_t (*amdgpu_block_rreg_t)(struct amdgpu_device*, uint32_t, uint32_t);
1937typedef void (*amdgpu_block_wreg_t)(struct amdgpu_device*, uint32_t, uint32_t, uint32_t);
1938
Alex Deucher8faf0e02015-07-28 11:50:31 -04001939struct amdgpu_ip_block_status {
1940 bool valid;
1941 bool sw;
1942 bool hw;
Chunming Zhou63fbf422016-07-15 11:19:20 +08001943 bool hang;
Alex Deucher8faf0e02015-07-28 11:50:31 -04001944};
1945
Alex Deucher97b2e202015-04-20 16:51:00 -04001946struct amdgpu_device {
1947 struct device *dev;
1948 struct drm_device *ddev;
1949 struct pci_dev *pdev;
Alex Deucher97b2e202015-04-20 16:51:00 -04001950
Maruthi Bayyavarapua8fe58c2015-09-22 17:05:20 -04001951#ifdef CONFIG_DRM_AMD_ACP
1952 struct amdgpu_acp acp;
1953#endif
1954
Alex Deucher97b2e202015-04-20 16:51:00 -04001955 /* ASIC */
Jammy Zhou2f7d10b2015-07-22 11:29:01 +08001956 enum amd_asic_type asic_type;
Alex Deucher97b2e202015-04-20 16:51:00 -04001957 uint32_t family;
1958 uint32_t rev_id;
1959 uint32_t external_rev_id;
1960 unsigned long flags;
1961 int usec_timeout;
1962 const struct amdgpu_asic_funcs *asic_funcs;
1963 bool shutdown;
Alex Deucher97b2e202015-04-20 16:51:00 -04001964 bool need_dma32;
1965 bool accel_working;
Christian Königedf600d2016-05-03 15:54:54 +02001966 struct work_struct reset_work;
Alex Deucher97b2e202015-04-20 16:51:00 -04001967 struct notifier_block acpi_nb;
1968 struct amdgpu_i2c_chan *i2c_bus[AMDGPU_MAX_I2C_BUS];
1969 struct amdgpu_debugfs debugfs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Christian Königedf600d2016-05-03 15:54:54 +02001970 unsigned debugfs_count;
Alex Deucher97b2e202015-04-20 16:51:00 -04001971#if defined(CONFIG_DEBUG_FS)
Tom St Denisadcec282016-04-15 13:08:44 -04001972 struct dentry *debugfs_regs[AMDGPU_DEBUGFS_MAX_COMPONENTS];
Alex Deucher97b2e202015-04-20 16:51:00 -04001973#endif
1974 struct amdgpu_atif atif;
1975 struct amdgpu_atcs atcs;
1976 struct mutex srbm_mutex;
1977 /* GRBM index mutex. Protects concurrent access to GRBM index */
1978 struct mutex grbm_idx_mutex;
1979 struct dev_pm_domain vga_pm_domain;
1980 bool have_disp_power_ref;
1981
1982 /* BIOS */
1983 uint8_t *bios;
1984 bool is_atom_bios;
Alex Deucher97b2e202015-04-20 16:51:00 -04001985 struct amdgpu_bo *stollen_vga_memory;
1986 uint32_t bios_scratch[AMDGPU_BIOS_NUM_SCRATCH];
1987
1988 /* Register/doorbell mmio */
1989 resource_size_t rmmio_base;
1990 resource_size_t rmmio_size;
1991 void __iomem *rmmio;
1992 /* protects concurrent MM_INDEX/DATA based register access */
1993 spinlock_t mmio_idx_lock;
1994 /* protects concurrent SMC based register access */
1995 spinlock_t smc_idx_lock;
1996 amdgpu_rreg_t smc_rreg;
1997 amdgpu_wreg_t smc_wreg;
1998 /* protects concurrent PCIE register access */
1999 spinlock_t pcie_idx_lock;
2000 amdgpu_rreg_t pcie_rreg;
2001 amdgpu_wreg_t pcie_wreg;
2002 /* protects concurrent UVD register access */
2003 spinlock_t uvd_ctx_idx_lock;
2004 amdgpu_rreg_t uvd_ctx_rreg;
2005 amdgpu_wreg_t uvd_ctx_wreg;
2006 /* protects concurrent DIDT register access */
2007 spinlock_t didt_idx_lock;
2008 amdgpu_rreg_t didt_rreg;
2009 amdgpu_wreg_t didt_wreg;
Rex Zhuccdbb202016-06-08 12:47:41 +08002010 /* protects concurrent gc_cac register access */
2011 spinlock_t gc_cac_idx_lock;
2012 amdgpu_rreg_t gc_cac_rreg;
2013 amdgpu_wreg_t gc_cac_wreg;
Alex Deucher97b2e202015-04-20 16:51:00 -04002014 /* protects concurrent ENDPOINT (audio) register access */
2015 spinlock_t audio_endpt_idx_lock;
2016 amdgpu_block_rreg_t audio_endpt_rreg;
2017 amdgpu_block_wreg_t audio_endpt_wreg;
2018 void __iomem *rio_mem;
2019 resource_size_t rio_mem_size;
2020 struct amdgpu_doorbell doorbell;
2021
2022 /* clock/pll info */
2023 struct amdgpu_clock clock;
2024
2025 /* MC */
2026 struct amdgpu_mc mc;
2027 struct amdgpu_gart gart;
2028 struct amdgpu_dummy_page dummy_page;
2029 struct amdgpu_vm_manager vm_manager;
2030
2031 /* memory management */
2032 struct amdgpu_mman mman;
Alex Deucher97b2e202015-04-20 16:51:00 -04002033 struct amdgpu_vram_scratch vram_scratch;
2034 struct amdgpu_wb wb;
2035 atomic64_t vram_usage;
2036 atomic64_t vram_vis_usage;
2037 atomic64_t gtt_usage;
2038 atomic64_t num_bytes_moved;
Christian Königdbd5ed62016-06-21 16:28:14 +02002039 atomic64_t num_evictions;
Marek Olšákd94aed52015-05-05 21:13:49 +02002040 atomic_t gpu_reset_counter;
Alex Deucher97b2e202015-04-20 16:51:00 -04002041
2042 /* display */
Emily Deng9accf2f2016-08-10 16:01:25 +08002043 bool enable_virtual_display;
Alex Deucher97b2e202015-04-20 16:51:00 -04002044 struct amdgpu_mode_info mode_info;
2045 struct work_struct hotplug_work;
2046 struct amdgpu_irq_src crtc_irq;
2047 struct amdgpu_irq_src pageflip_irq;
2048 struct amdgpu_irq_src hpd_irq;
2049
2050 /* rings */
Christian König76bf0db2016-06-01 15:10:02 +02002051 u64 fence_context;
Alex Deucher97b2e202015-04-20 16:51:00 -04002052 unsigned num_rings;
2053 struct amdgpu_ring *rings[AMDGPU_MAX_RINGS];
2054 bool ib_pool_ready;
2055 struct amdgpu_sa_manager ring_tmp_bo;
2056
2057 /* interrupts */
2058 struct amdgpu_irq irq;
2059
Alex Deucher1f7371b2015-12-02 17:46:21 -05002060 /* powerplay */
2061 struct amd_powerplay powerplay;
Jammy Zhoue61710c2015-11-10 18:31:08 -05002062 bool pp_enabled;
Eric Huangf3898ea2015-12-11 16:24:34 -05002063 bool pp_force_state_enabled;
Alex Deucher1f7371b2015-12-02 17:46:21 -05002064
Alex Deucher97b2e202015-04-20 16:51:00 -04002065 /* dpm */
2066 struct amdgpu_pm pm;
2067 u32 cg_flags;
2068 u32 pg_flags;
2069
2070 /* amdgpu smumgr */
2071 struct amdgpu_smumgr smu;
2072
2073 /* gfx */
2074 struct amdgpu_gfx gfx;
2075
2076 /* sdma */
Alex Deucherc113ea12015-10-08 16:30:37 -04002077 struct amdgpu_sdma sdma;
Alex Deucher97b2e202015-04-20 16:51:00 -04002078
2079 /* uvd */
Alex Deucher97b2e202015-04-20 16:51:00 -04002080 struct amdgpu_uvd uvd;
2081
2082 /* vce */
2083 struct amdgpu_vce vce;
2084
2085 /* firmwares */
2086 struct amdgpu_firmware firmware;
2087
2088 /* GDS */
2089 struct amdgpu_gds gds;
2090
2091 const struct amdgpu_ip_block_version *ip_blocks;
2092 int num_ip_blocks;
Alex Deucher8faf0e02015-07-28 11:50:31 -04002093 struct amdgpu_ip_block_status *ip_block_status;
Alex Deucher97b2e202015-04-20 16:51:00 -04002094 struct mutex mn_lock;
2095 DECLARE_HASHTABLE(mn_hash, 7);
2096
2097 /* tracking pinned memory */
2098 u64 vram_pin_size;
Chunming Zhoue131b912016-04-05 10:48:48 +08002099 u64 invisible_pin_size;
Alex Deucher97b2e202015-04-20 16:51:00 -04002100 u64 gart_pin_size;
Oded Gabbay130e0372015-06-12 21:35:14 +03002101
2102 /* amdkfd interface */
2103 struct kfd_dev *kfd;
Chunming Zhou23ca0e42015-07-06 13:42:58 +08002104
Alex Deucher7e471e62016-02-01 11:13:04 -05002105 struct amdgpu_virtualization virtualization;
Alex Deucher97b2e202015-04-20 16:51:00 -04002106};
2107
2108bool amdgpu_device_is_px(struct drm_device *dev);
2109int amdgpu_device_init(struct amdgpu_device *adev,
2110 struct drm_device *ddev,
2111 struct pci_dev *pdev,
2112 uint32_t flags);
2113void amdgpu_device_fini(struct amdgpu_device *adev);
2114int amdgpu_gpu_wait_for_idle(struct amdgpu_device *adev);
2115
2116uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
2117 bool always_indirect);
2118void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
2119 bool always_indirect);
2120u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg);
2121void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v);
2122
2123u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index);
2124void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v);
2125
2126/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002127 * Registers read & write functions.
2128 */
2129#define RREG32(reg) amdgpu_mm_rreg(adev, (reg), false)
2130#define RREG32_IDX(reg) amdgpu_mm_rreg(adev, (reg), true)
2131#define DREG32(reg) printk(KERN_INFO "REGISTER: " #reg " : 0x%08X\n", amdgpu_mm_rreg(adev, (reg), false))
2132#define WREG32(reg, v) amdgpu_mm_wreg(adev, (reg), (v), false)
2133#define WREG32_IDX(reg, v) amdgpu_mm_wreg(adev, (reg), (v), true)
2134#define REG_SET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2135#define REG_GET(FIELD, v) (((v) << FIELD##_SHIFT) & FIELD##_MASK)
2136#define RREG32_PCIE(reg) adev->pcie_rreg(adev, (reg))
2137#define WREG32_PCIE(reg, v) adev->pcie_wreg(adev, (reg), (v))
2138#define RREG32_SMC(reg) adev->smc_rreg(adev, (reg))
2139#define WREG32_SMC(reg, v) adev->smc_wreg(adev, (reg), (v))
2140#define RREG32_UVD_CTX(reg) adev->uvd_ctx_rreg(adev, (reg))
2141#define WREG32_UVD_CTX(reg, v) adev->uvd_ctx_wreg(adev, (reg), (v))
2142#define RREG32_DIDT(reg) adev->didt_rreg(adev, (reg))
2143#define WREG32_DIDT(reg, v) adev->didt_wreg(adev, (reg), (v))
Rex Zhuccdbb202016-06-08 12:47:41 +08002144#define RREG32_GC_CAC(reg) adev->gc_cac_rreg(adev, (reg))
2145#define WREG32_GC_CAC(reg, v) adev->gc_cac_wreg(adev, (reg), (v))
Alex Deucher97b2e202015-04-20 16:51:00 -04002146#define RREG32_AUDIO_ENDPT(block, reg) adev->audio_endpt_rreg(adev, (block), (reg))
2147#define WREG32_AUDIO_ENDPT(block, reg, v) adev->audio_endpt_wreg(adev, (block), (reg), (v))
2148#define WREG32_P(reg, val, mask) \
2149 do { \
2150 uint32_t tmp_ = RREG32(reg); \
2151 tmp_ &= (mask); \
2152 tmp_ |= ((val) & ~(mask)); \
2153 WREG32(reg, tmp_); \
2154 } while (0)
2155#define WREG32_AND(reg, and) WREG32_P(reg, 0, and)
2156#define WREG32_OR(reg, or) WREG32_P(reg, or, ~(or))
2157#define WREG32_PLL_P(reg, val, mask) \
2158 do { \
2159 uint32_t tmp_ = RREG32_PLL(reg); \
2160 tmp_ &= (mask); \
2161 tmp_ |= ((val) & ~(mask)); \
2162 WREG32_PLL(reg, tmp_); \
2163 } while (0)
2164#define DREG32_SYS(sqf, adev, reg) seq_printf((sqf), #reg " : 0x%08X\n", amdgpu_mm_rreg((adev), (reg), false))
2165#define RREG32_IO(reg) amdgpu_io_rreg(adev, (reg))
2166#define WREG32_IO(reg, v) amdgpu_io_wreg(adev, (reg), (v))
2167
2168#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
2169#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))
2170
2171#define REG_FIELD_SHIFT(reg, field) reg##__##field##__SHIFT
2172#define REG_FIELD_MASK(reg, field) reg##__##field##_MASK
2173
2174#define REG_SET_FIELD(orig_val, reg, field, field_val) \
2175 (((orig_val) & ~REG_FIELD_MASK(reg, field)) | \
2176 (REG_FIELD_MASK(reg, field) & ((field_val) << REG_FIELD_SHIFT(reg, field))))
2177
2178#define REG_GET_FIELD(value, reg, field) \
2179 (((value) & REG_FIELD_MASK(reg, field)) >> REG_FIELD_SHIFT(reg, field))
2180
Tom St Denis61cb8ce2016-08-09 10:13:21 -04002181#define WREG32_FIELD(reg, field, val) \
2182 WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
2183
Alex Deucher97b2e202015-04-20 16:51:00 -04002184/*
2185 * BIOS helpers.
2186 */
2187#define RBIOS8(i) (adev->bios[i])
2188#define RBIOS16(i) (RBIOS8(i) | (RBIOS8((i)+1) << 8))
2189#define RBIOS32(i) ((RBIOS16(i)) | (RBIOS16((i)+2) << 16))
2190
2191/*
2192 * RING helpers.
2193 */
2194static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
2195{
2196 if (ring->count_dw <= 0)
Jammy Zhou86c2b792015-05-13 22:52:42 +08002197 DRM_ERROR("amdgpu: writing more dwords to the ring than expected!\n");
Alex Deucher97b2e202015-04-20 16:51:00 -04002198 ring->ring[ring->wptr++] = v;
2199 ring->wptr &= ring->ptr_mask;
2200 ring->count_dw--;
Alex Deucher97b2e202015-04-20 16:51:00 -04002201}
2202
Alex Deucherc113ea12015-10-08 16:30:37 -04002203static inline struct amdgpu_sdma_instance *
2204amdgpu_get_sdma_instance(struct amdgpu_ring *ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002205{
2206 struct amdgpu_device *adev = ring->adev;
2207 int i;
2208
Alex Deucherc113ea12015-10-08 16:30:37 -04002209 for (i = 0; i < adev->sdma.num_instances; i++)
2210 if (&adev->sdma.instance[i].ring == ring)
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002211 break;
2212
2213 if (i < AMDGPU_MAX_SDMA_INSTANCES)
Alex Deucherc113ea12015-10-08 16:30:37 -04002214 return &adev->sdma.instance[i];
Jammy Zhou4b2f7e22015-09-01 12:56:17 +08002215 else
2216 return NULL;
2217}
2218
Alex Deucher97b2e202015-04-20 16:51:00 -04002219/*
2220 * ASICs macro.
2221 */
2222#define amdgpu_asic_set_vga_state(adev, state) (adev)->asic_funcs->set_vga_state((adev), (state))
2223#define amdgpu_asic_reset(adev) (adev)->asic_funcs->reset((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002224#define amdgpu_asic_get_xclk(adev) (adev)->asic_funcs->get_xclk((adev))
2225#define amdgpu_asic_set_uvd_clocks(adev, v, d) (adev)->asic_funcs->set_uvd_clocks((adev), (v), (d))
2226#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 -04002227#define amdgpu_asic_get_virtual_caps(adev) ((adev)->asic_funcs->get_virtual_caps((adev)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002228#define amdgpu_asic_read_disabled_bios(adev) (adev)->asic_funcs->read_disabled_bios((adev))
Alex Deucher7946b872015-11-24 10:14:28 -05002229#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 -04002230#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 -04002231#define amdgpu_gart_flush_gpu_tlb(adev, vmid) (adev)->gart.gart_funcs->flush_gpu_tlb((adev), (vmid))
2232#define amdgpu_gart_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gart.gart_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
2233#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 +02002234#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 -04002235#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 -04002236#define amdgpu_ring_parse_cs(r, p, ib) ((r)->funcs->parse_cs((p), (ib)))
2237#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
Christian Königbbec97a2016-07-05 21:07:17 +02002238#define amdgpu_ring_test_ib(r, t) (r)->funcs->test_ib((r), (t))
Alex Deucher97b2e202015-04-20 16:51:00 -04002239#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
2240#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
2241#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
Christian Königd88bf582016-05-06 17:50:03 +02002242#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 +01002243#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
Alex Deucher97b2e202015-04-20 16:51:00 -04002244#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
Chunming Zhou890ee232015-06-01 14:35:03 +08002245#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
Alex Deucher97b2e202015-04-20 16:51:00 -04002246#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 +02002247#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
Chunming Zhou11afbde2016-03-03 11:38:48 +08002248#define amdgpu_ring_emit_hdp_invalidate(r) (r)->funcs->emit_hdp_invalidate((r))
Christian König9e5d53092016-01-31 12:20:55 +01002249#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
Monk Liu03ccf482016-01-14 19:07:38 +08002250#define amdgpu_ring_init_cond_exec(r) (r)->funcs->init_cond_exec((r))
2251#define amdgpu_ring_patch_cond_exec(r,o) (r)->funcs->patch_cond_exec((r),(o))
Alex Deucher97b2e202015-04-20 16:51:00 -04002252#define amdgpu_ih_get_wptr(adev) (adev)->irq.ih_funcs->get_wptr((adev))
2253#define amdgpu_ih_decode_iv(adev, iv) (adev)->irq.ih_funcs->decode_iv((adev), (iv))
2254#define amdgpu_ih_set_rptr(adev) (adev)->irq.ih_funcs->set_rptr((adev))
2255#define amdgpu_display_set_vga_render_state(adev, r) (adev)->mode_info.funcs->set_vga_render_state((adev), (r))
2256#define amdgpu_display_vblank_get_counter(adev, crtc) (adev)->mode_info.funcs->vblank_get_counter((adev), (crtc))
2257#define amdgpu_display_vblank_wait(adev, crtc) (adev)->mode_info.funcs->vblank_wait((adev), (crtc))
2258#define amdgpu_display_is_display_hung(adev) (adev)->mode_info.funcs->is_display_hung((adev))
2259#define amdgpu_display_backlight_set_level(adev, e, l) (adev)->mode_info.funcs->backlight_set_level((e), (l))
2260#define amdgpu_display_backlight_get_level(adev, e) (adev)->mode_info.funcs->backlight_get_level((e))
2261#define amdgpu_display_hpd_sense(adev, h) (adev)->mode_info.funcs->hpd_sense((adev), (h))
2262#define amdgpu_display_hpd_set_polarity(adev, h) (adev)->mode_info.funcs->hpd_set_polarity((adev), (h))
2263#define amdgpu_display_hpd_get_gpio_reg(adev) (adev)->mode_info.funcs->hpd_get_gpio_reg((adev))
2264#define amdgpu_display_bandwidth_update(adev) (adev)->mode_info.funcs->bandwidth_update((adev))
Alex Deuchercb9e59d2016-05-05 16:03:57 -04002265#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 -04002266#define amdgpu_display_page_flip_get_scanoutpos(adev, crtc, vbl, pos) (adev)->mode_info.funcs->page_flip_get_scanoutpos((adev), (crtc), (vbl), (pos))
2267#define amdgpu_display_add_encoder(adev, e, s, c) (adev)->mode_info.funcs->add_encoder((adev), (e), (s), (c))
2268#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))
2269#define amdgpu_display_stop_mc_access(adev, s) (adev)->mode_info.funcs->stop_mc_access((adev), (s))
2270#define amdgpu_display_resume_mc_access(adev, s) (adev)->mode_info.funcs->resume_mc_access((adev), (s))
Chunming Zhouc7ae72c2015-08-25 17:23:45 +08002271#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 +08002272#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 -04002273#define amdgpu_dpm_pre_set_power_state(adev) (adev)->pm.funcs->pre_set_power_state((adev))
2274#define amdgpu_dpm_set_power_state(adev) (adev)->pm.funcs->set_power_state((adev))
2275#define amdgpu_dpm_post_set_power_state(adev) (adev)->pm.funcs->post_set_power_state((adev))
2276#define amdgpu_dpm_display_configuration_changed(adev) (adev)->pm.funcs->display_configuration_changed((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002277#define amdgpu_dpm_print_power_state(adev, ps) (adev)->pm.funcs->print_power_state((adev), (ps))
Alex Deucher97b2e202015-04-20 16:51:00 -04002278#define amdgpu_dpm_vblank_too_short(adev) (adev)->pm.funcs->vblank_too_short((adev))
Alex Deucher97b2e202015-04-20 16:51:00 -04002279#define amdgpu_dpm_enable_bapm(adev, e) (adev)->pm.funcs->enable_bapm((adev), (e))
Alex Deucherb95e31f2016-07-07 15:01:42 -04002280#define amdgpu_gfx_get_gpu_clock_counter(adev) (adev)->gfx.funcs->get_gpu_clock_counter((adev))
Tom St Denis9559ef52016-06-28 10:26:48 -04002281#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 +08002282
2283#define amdgpu_dpm_get_temperature(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002284 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002285 (adev)->powerplay.pp_funcs->get_temperature((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002286 (adev)->pm.funcs->get_temperature((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002287
2288#define amdgpu_dpm_set_fan_control_mode(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002289 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002290 (adev)->powerplay.pp_funcs->set_fan_control_mode((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002291 (adev)->pm.funcs->set_fan_control_mode((adev), (m)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002292
2293#define amdgpu_dpm_get_fan_control_mode(adev) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002294 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002295 (adev)->powerplay.pp_funcs->get_fan_control_mode((adev)->powerplay.pp_handle) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002296 (adev)->pm.funcs->get_fan_control_mode((adev)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002297
2298#define amdgpu_dpm_set_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002299 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002300 (adev)->powerplay.pp_funcs->set_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002301 (adev)->pm.funcs->set_fan_speed_percent((adev), (s)))
Rex Zhu3af76f22015-10-15 17:23:43 +08002302
2303#define amdgpu_dpm_get_fan_speed_percent(adev, s) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002304 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002305 (adev)->powerplay.pp_funcs->get_fan_speed_percent((adev)->powerplay.pp_handle, (s)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002306 (adev)->pm.funcs->get_fan_speed_percent((adev), (s)))
Alex Deucher97b2e202015-04-20 16:51:00 -04002307
Rex Zhu1b5708f2015-11-10 18:25:24 -05002308#define amdgpu_dpm_get_sclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002309 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002310 (adev)->powerplay.pp_funcs->get_sclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002311 (adev)->pm.funcs->get_sclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002312
2313#define amdgpu_dpm_get_mclk(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002314 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002315 (adev)->powerplay.pp_funcs->get_mclk((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002316 (adev)->pm.funcs->get_mclk((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002317
2318
2319#define amdgpu_dpm_force_performance_level(adev, l) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002320 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002321 (adev)->powerplay.pp_funcs->force_performance_level((adev)->powerplay.pp_handle, (l)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002322 (adev)->pm.funcs->force_performance_level((adev), (l)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002323
2324#define amdgpu_dpm_powergate_uvd(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002325 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002326 (adev)->powerplay.pp_funcs->powergate_uvd((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002327 (adev)->pm.funcs->powergate_uvd((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002328
2329#define amdgpu_dpm_powergate_vce(adev, g) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002330 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002331 (adev)->powerplay.pp_funcs->powergate_vce((adev)->powerplay.pp_handle, (g)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002332 (adev)->pm.funcs->powergate_vce((adev), (g)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002333
2334#define amdgpu_dpm_debugfs_print_current_performance_level(adev, m) \
Eric Huang4b5ece22016-01-19 14:28:56 -05002335 ((adev)->pp_enabled ? \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002336 (adev)->powerplay.pp_funcs->print_current_performance_level((adev)->powerplay.pp_handle, (m)) : \
Eric Huang4b5ece22016-01-19 14:28:56 -05002337 (adev)->pm.funcs->debugfs_print_current_performance_level((adev), (m)))
Rex Zhu1b5708f2015-11-10 18:25:24 -05002338
2339#define amdgpu_dpm_get_current_power_state(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002340 (adev)->powerplay.pp_funcs->get_current_power_state((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002341
2342#define amdgpu_dpm_get_performance_level(adev) \
Jammy Zhoue61710c2015-11-10 18:31:08 -05002343 (adev)->powerplay.pp_funcs->get_performance_level((adev)->powerplay.pp_handle)
Rex Zhu1b5708f2015-11-10 18:25:24 -05002344
Eric Huangf3898ea2015-12-11 16:24:34 -05002345#define amdgpu_dpm_get_pp_num_states(adev, data) \
2346 (adev)->powerplay.pp_funcs->get_pp_num_states((adev)->powerplay.pp_handle, data)
2347
2348#define amdgpu_dpm_get_pp_table(adev, table) \
2349 (adev)->powerplay.pp_funcs->get_pp_table((adev)->powerplay.pp_handle, table)
2350
2351#define amdgpu_dpm_set_pp_table(adev, buf, size) \
2352 (adev)->powerplay.pp_funcs->set_pp_table((adev)->powerplay.pp_handle, buf, size)
2353
2354#define amdgpu_dpm_print_clock_levels(adev, type, buf) \
2355 (adev)->powerplay.pp_funcs->print_clock_levels((adev)->powerplay.pp_handle, type, buf)
2356
2357#define amdgpu_dpm_force_clock_level(adev, type, level) \
2358 (adev)->powerplay.pp_funcs->force_clock_level((adev)->powerplay.pp_handle, type, level)
2359
Eric Huang428bafa2016-05-12 14:51:21 -04002360#define amdgpu_dpm_get_sclk_od(adev) \
2361 (adev)->powerplay.pp_funcs->get_sclk_od((adev)->powerplay.pp_handle)
2362
2363#define amdgpu_dpm_set_sclk_od(adev, value) \
2364 (adev)->powerplay.pp_funcs->set_sclk_od((adev)->powerplay.pp_handle, value)
2365
Eric Huangf2bdc052016-05-24 15:11:17 -04002366#define amdgpu_dpm_get_mclk_od(adev) \
2367 ((adev)->powerplay.pp_funcs->get_mclk_od((adev)->powerplay.pp_handle))
2368
2369#define amdgpu_dpm_set_mclk_od(adev, value) \
2370 ((adev)->powerplay.pp_funcs->set_mclk_od((adev)->powerplay.pp_handle, value))
2371
Jammy Zhoue61710c2015-11-10 18:31:08 -05002372#define amdgpu_dpm_dispatch_task(adev, event_id, input, output) \
Rex Zhu1b5708f2015-11-10 18:25:24 -05002373 (adev)->powerplay.pp_funcs->dispatch_tasks((adev)->powerplay.pp_handle, (event_id), (input), (output))
Alex Deucher97b2e202015-04-20 16:51:00 -04002374
2375#define amdgpu_gds_switch(adev, r, v, d, w, a) (adev)->gds.funcs->patch_gds_switch((r), (v), (d), (w), (a))
2376
2377/* Common functions */
2378int amdgpu_gpu_reset(struct amdgpu_device *adev);
2379void amdgpu_pci_config_reset(struct amdgpu_device *adev);
2380bool amdgpu_card_posted(struct amdgpu_device *adev);
2381void amdgpu_update_display_priority(struct amdgpu_device *adev);
Chunming Zhoud5fc5e82015-07-21 16:52:10 +08002382
Alex Deucher97b2e202015-04-20 16:51:00 -04002383int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, void *data);
2384int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
2385 u32 ip_instance, u32 ring,
2386 struct amdgpu_ring **out_ring);
2387void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *rbo, u32 domain);
2388bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
Christian König2f568db2016-02-23 12:36:59 +01002389int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page **pages);
Alex Deucher97b2e202015-04-20 16:51:00 -04002390int amdgpu_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
2391 uint32_t flags);
2392bool amdgpu_ttm_tt_has_userptr(struct ttm_tt *ttm);
Christian Königcc325d12016-02-08 11:08:35 +01002393struct mm_struct *amdgpu_ttm_tt_get_usermm(struct ttm_tt *ttm);
Christian Königd7006962016-02-08 10:57:22 +01002394bool amdgpu_ttm_tt_affect_userptr(struct ttm_tt *ttm, unsigned long start,
2395 unsigned long end);
Christian König2f568db2016-02-23 12:36:59 +01002396bool amdgpu_ttm_tt_userptr_invalidated(struct ttm_tt *ttm,
2397 int *last_invalidated);
Alex Deucher97b2e202015-04-20 16:51:00 -04002398bool amdgpu_ttm_tt_is_readonly(struct ttm_tt *ttm);
2399uint32_t amdgpu_ttm_tt_pte_flags(struct amdgpu_device *adev, struct ttm_tt *ttm,
2400 struct ttm_mem_reg *mem);
2401void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base);
2402void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc);
2403void amdgpu_ttm_set_active_vram_size(struct amdgpu_device *adev, u64 size);
Ken Wanga693e052016-07-27 19:18:01 +08002404u64 amdgpu_ttm_get_gtt_mem_size(struct amdgpu_device *adev);
2405int amdgpu_ttm_global_init(struct amdgpu_device *adev);
Alex Deucher97b2e202015-04-20 16:51:00 -04002406void amdgpu_program_register_sequence(struct amdgpu_device *adev,
2407 const u32 *registers,
2408 const u32 array_size);
2409
2410bool amdgpu_device_is_px(struct drm_device *dev);
2411/* atpx handler */
2412#if defined(CONFIG_VGA_SWITCHEROO)
2413void amdgpu_register_atpx_handler(void);
2414void amdgpu_unregister_atpx_handler(void);
Alex Deuchera78fe132016-06-01 13:08:21 -04002415bool amdgpu_has_atpx_dgpu_power_cntl(void);
Alex Deucher2f5af822016-06-02 09:04:01 -04002416bool amdgpu_is_atpx_hybrid(void);
Alex Deucher97b2e202015-04-20 16:51:00 -04002417#else
2418static inline void amdgpu_register_atpx_handler(void) {}
2419static inline void amdgpu_unregister_atpx_handler(void) {}
Alex Deuchera78fe132016-06-01 13:08:21 -04002420static inline bool amdgpu_has_atpx_dgpu_power_cntl(void) { return false; }
Alex Deucher2f5af822016-06-02 09:04:01 -04002421static inline bool amdgpu_is_atpx_hybrid(void) { return false; }
Alex Deucher97b2e202015-04-20 16:51:00 -04002422#endif
2423
2424/*
2425 * KMS
2426 */
2427extern const struct drm_ioctl_desc amdgpu_ioctls_kms[];
Nils Wallméniusf498d9e2016-04-10 16:29:59 +02002428extern const int amdgpu_max_kms_ioctl;
Alex Deucher97b2e202015-04-20 16:51:00 -04002429
2430int amdgpu_driver_load_kms(struct drm_device *dev, unsigned long flags);
2431int amdgpu_driver_unload_kms(struct drm_device *dev);
2432void amdgpu_driver_lastclose_kms(struct drm_device *dev);
2433int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv);
2434void amdgpu_driver_postclose_kms(struct drm_device *dev,
2435 struct drm_file *file_priv);
2436void amdgpu_driver_preclose_kms(struct drm_device *dev,
2437 struct drm_file *file_priv);
2438int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon);
2439int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
Thierry Reding88e72712015-09-24 18:35:31 +02002440u32 amdgpu_get_vblank_counter_kms(struct drm_device *dev, unsigned int pipe);
2441int amdgpu_enable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2442void amdgpu_disable_vblank_kms(struct drm_device *dev, unsigned int pipe);
2443int amdgpu_get_vblank_timestamp_kms(struct drm_device *dev, unsigned int pipe,
Alex Deucher97b2e202015-04-20 16:51:00 -04002444 int *max_error,
2445 struct timeval *vblank_time,
2446 unsigned flags);
2447long amdgpu_kms_compat_ioctl(struct file *filp, unsigned int cmd,
2448 unsigned long arg);
2449
2450/*
Alex Deucher97b2e202015-04-20 16:51:00 -04002451 * functions used by amdgpu_encoder.c
2452 */
2453struct amdgpu_afmt_acr {
2454 u32 clock;
2455
2456 int n_32khz;
2457 int cts_32khz;
2458
2459 int n_44_1khz;
2460 int cts_44_1khz;
2461
2462 int n_48khz;
2463 int cts_48khz;
2464
2465};
2466
2467struct amdgpu_afmt_acr amdgpu_afmt_acr(uint32_t clock);
2468
2469/* amdgpu_acpi.c */
2470#if defined(CONFIG_ACPI)
2471int amdgpu_acpi_init(struct amdgpu_device *adev);
2472void amdgpu_acpi_fini(struct amdgpu_device *adev);
2473bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev);
2474int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
2475 u8 perf_req, bool advertise);
2476int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev);
2477#else
2478static inline int amdgpu_acpi_init(struct amdgpu_device *adev) { return 0; }
2479static inline void amdgpu_acpi_fini(struct amdgpu_device *adev) { }
2480#endif
2481
2482struct amdgpu_bo_va_mapping *
2483amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
2484 uint64_t addr, struct amdgpu_bo **bo);
2485
2486#include "amdgpu_object.h"
Alex Deucher97b2e202015-04-20 16:51:00 -04002487#endif