Merge tag 'pci-v6.16-fixes-3' of git://git.kernel.org/pub/scm/linux/kernel/git/pci/pci
[linux-block.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_ring.h
CommitLineData
78023016
CK
1/*
2 * Copyright 2016 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Christian König
23 */
24#ifndef __AMDGPU_RING_H__
25#define __AMDGPU_RING_H__
26
b2ff0e8a 27#include <drm/amdgpu_drm.h>
1b1f42d8 28#include <drm/gpu_scheduler.h>
61b100e9 29#include <drm/drm_print.h>
c103a23f 30#include <drm/drm_suballoc.h>
78023016 31
a190f8dc
CK
32struct amdgpu_device;
33struct amdgpu_ring;
34struct amdgpu_ib;
35struct amdgpu_cs_parser;
36struct amdgpu_job;
37struct amdgpu_vm;
38
78023016 39/* max number of rings */
ea6dd40c 40#define AMDGPU_MAX_RINGS 149
1bd99ca2 41#define AMDGPU_MAX_HWIP_RINGS 64
a644d85a 42#define AMDGPU_MAX_GFX_RINGS 2
0c97a19a 43#define AMDGPU_MAX_SW_GFX_RINGS 2
78023016
CK
44#define AMDGPU_MAX_COMPUTE_RINGS 8
45#define AMDGPU_MAX_VCE_RINGS 3
f7243053 46#define AMDGPU_MAX_UVD_ENC_RINGS 2
2d6ea3b0 47#define AMDGPU_MAX_VPE_RINGS 2
78023016 48
34eaf30f
ND
49enum amdgpu_ring_priority_level {
50 AMDGPU_RING_PRIO_0,
51 AMDGPU_RING_PRIO_1,
52 AMDGPU_RING_PRIO_DEFAULT = 1,
53 AMDGPU_RING_PRIO_2,
54 AMDGPU_RING_PRIO_MAX
55};
1c6d567b 56
78023016 57/* some special values for the owner field */
d8d019cc
FK
58#define AMDGPU_FENCE_OWNER_UNDEFINED ((void *)0ul)
59#define AMDGPU_FENCE_OWNER_VM ((void *)1ul)
60#define AMDGPU_FENCE_OWNER_KFD ((void *)2ul)
78023016
CK
61
62#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
63#define AMDGPU_FENCE_FLAG_INT (1 << 1)
d240cd9e 64#define AMDGPU_FENCE_FLAG_TC_WB_ONLY (1 << 2)
be254550 65#define AMDGPU_FENCE_FLAG_EXEC (1 << 3)
78023016 66
0e28b10f
CK
67#define to_amdgpu_ring(s) container_of((s), struct amdgpu_ring, sched)
68
9ecefb19
CK
69#define AMDGPU_IB_POOL_SIZE (1024 * 1024)
70
78023016 71enum amdgpu_ring_type {
07e14845
ND
72 AMDGPU_RING_TYPE_GFX = AMDGPU_HW_IP_GFX,
73 AMDGPU_RING_TYPE_COMPUTE = AMDGPU_HW_IP_COMPUTE,
74 AMDGPU_RING_TYPE_SDMA = AMDGPU_HW_IP_DMA,
75 AMDGPU_RING_TYPE_UVD = AMDGPU_HW_IP_UVD,
76 AMDGPU_RING_TYPE_VCE = AMDGPU_HW_IP_VCE,
77 AMDGPU_RING_TYPE_UVD_ENC = AMDGPU_HW_IP_UVD_ENC,
78 AMDGPU_RING_TYPE_VCN_DEC = AMDGPU_HW_IP_VCN_DEC,
79 AMDGPU_RING_TYPE_VCN_ENC = AMDGPU_HW_IP_VCN_ENC,
80 AMDGPU_RING_TYPE_VCN_JPEG = AMDGPU_HW_IP_VCN_JPEG,
2d6ea3b0 81 AMDGPU_RING_TYPE_VPE = AMDGPU_HW_IP_VPE,
cdca7979 82 AMDGPU_RING_TYPE_KIQ,
1a29f367
LY
83 AMDGPU_RING_TYPE_MES,
84 AMDGPU_RING_TYPE_UMSCH_MM,
4d614ce8 85 AMDGPU_RING_TYPE_CPER,
78023016
CK
86};
87
9ecefb19
CK
88enum amdgpu_ib_pool_type {
89 /* Normal submissions to the top of the pipeline. */
90 AMDGPU_IB_POOL_DELAYED,
91 /* Immediate submissions to the bottom of the pipeline. */
92 AMDGPU_IB_POOL_IMMEDIATE,
93 /* Direct submission to the ring buffer during init and reset. */
94 AMDGPU_IB_POOL_DIRECT,
95
96 AMDGPU_IB_POOL_MAX
97};
98
a190f8dc 99struct amdgpu_ib {
c103a23f 100 struct drm_suballoc *sa_bo;
a190f8dc
CK
101 uint32_t length_dw;
102 uint64_t gpu_addr;
103 uint32_t *ptr;
104 uint32_t flags;
105};
78023016 106
1c6d567b
ND
107struct amdgpu_sched {
108 u32 num_scheds;
109 struct drm_gpu_scheduler *sched[AMDGPU_MAX_HWIP_RINGS];
110};
111
78023016
CK
112/*
113 * Fences.
114 */
115struct amdgpu_fence_driver {
116 uint64_t gpu_addr;
117 volatile uint32_t *cpu_addr;
118 /* sync_seq is protected by ring emission lock */
119 uint32_t sync_seq;
120 atomic_t last_seq;
121 bool initialized;
122 struct amdgpu_irq_src *irq_src;
123 unsigned irq_type;
8c5e13ec 124 struct timer_list fallback_timer;
78023016
CK
125 unsigned num_fences_mask;
126 spinlock_t lock;
220196b3 127 struct dma_fence **fences;
78023016
CK
128};
129
ebe43542
AD
130/*
131 * Fences mark an event in the GPUs pipeline and are used
132 * for GPU/CPU synchronization. When the fence is written,
133 * it is expected that all buffers associated with that fence
134 * are no longer in use by the associated ring on the GPU and
135 * that the relevant GPU caches have been flushed.
136 */
137
138struct amdgpu_fence {
139 struct dma_fence base;
140
141 /* RB, DMA, etc. */
142 struct amdgpu_ring *ring;
143 ktime_t start_timestamp;
144};
145
a190f8dc
CK
146extern const struct drm_sched_backend_ops amdgpu_sched_ops;
147
bf67014d 148void amdgpu_fence_driver_clear_job_fences(struct amdgpu_ring *ring);
b13eb02b 149void amdgpu_fence_driver_set_error(struct amdgpu_ring *ring, int error);
2f9d4084 150void amdgpu_fence_driver_force_completion(struct amdgpu_ring *ring);
78023016 151
5fd8518d 152int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
78023016
CK
153int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
154 struct amdgpu_irq_src *irq_src,
155 unsigned irq_type);
067f44c8 156void amdgpu_fence_driver_hw_init(struct amdgpu_device *adev);
8d35a259 157void amdgpu_fence_driver_hw_fini(struct amdgpu_device *adev);
067f44c8 158int amdgpu_fence_driver_sw_init(struct amdgpu_device *adev);
8d35a259 159void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev);
c530b02f 160int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence, struct amdgpu_job *job,
d240cd9e 161 unsigned flags);
04e4e2e9
YT
162int amdgpu_fence_emit_polling(struct amdgpu_ring *ring, uint32_t *s,
163 uint32_t timeout);
95d7fc4a 164bool amdgpu_fence_process(struct amdgpu_ring *ring);
78023016 165int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
43ca8efa 166signed long amdgpu_fence_wait_polling(struct amdgpu_ring *ring,
167 uint32_t wait_seq,
168 signed long timeout);
78023016 169unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
3f4c175d 170
9e225fb9 171void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop);
78023016 172
3f4c175d
JZ
173u64 amdgpu_fence_last_unsignaled_time_us(struct amdgpu_ring *ring);
174void amdgpu_fence_update_start_timestamp(struct amdgpu_ring *ring, uint32_t seq,
175 ktime_t timestamp);
176
78023016
CK
177/*
178 * Rings.
179 */
180
181/* provided by hw blocks that expose a ring buffer for commands */
182struct amdgpu_ring_funcs {
c8305c63
RS
183 /**
184 * @type:
185 *
186 * GFX, Compute, SDMA, UVD, VCE, VCN, VPE, KIQ, MES, UMSCH, and CPER
187 * use ring buffers. The type field just identifies which component the
188 * ring buffer is associated with.
189 */
21cd942e 190 enum amdgpu_ring_type type;
79887142 191 uint32_t align_mask;
c8305c63
RS
192
193 /**
194 * @nop:
195 *
196 * Every block in the amdgpu has no-op instructions (e.g., GFX 10
197 * uses PACKET3(PACKET3_NOP, 0x3FFF), VCN 5 uses VCN_ENC_CMD_NO_OP,
198 * etc). This field receives the specific no-op for the component
199 * that initializes the ring.
200 */
79887142 201 u32 nop;
536fbf94 202 bool support_64bit_ptrs;
120c2125 203 bool no_user_fence;
8c0f11ff 204 bool secure_submission_supported;
c8c1a1d2 205 unsigned extra_dw;
21cd942e 206
78023016 207 /* ring read/write ptr handling */
536fbf94
KW
208 u64 (*get_rptr)(struct amdgpu_ring *ring);
209 u64 (*get_wptr)(struct amdgpu_ring *ring);
78023016
CK
210 void (*set_wptr)(struct amdgpu_ring *ring);
211 /* validating and patching of IBs */
cdc7893f
CK
212 int (*parse_cs)(struct amdgpu_cs_parser *p,
213 struct amdgpu_job *job,
214 struct amdgpu_ib *ib);
215 int (*patch_cs_in_place)(struct amdgpu_cs_parser *p,
216 struct amdgpu_job *job,
217 struct amdgpu_ib *ib);
e12f3d7a
CK
218 /* constants to calculate how many DW are needed for an emit */
219 unsigned emit_frame_size;
220 unsigned emit_ib_size;
78023016
CK
221 /* command emit functions */
222 void (*emit_ib)(struct amdgpu_ring *ring,
34955e03 223 struct amdgpu_job *job,
78023016 224 struct amdgpu_ib *ib,
c4c905ec 225 uint32_t flags);
78023016
CK
226 void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
227 uint64_t seq, unsigned flags);
228 void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
c4f46f22 229 void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vmid,
c633c00b 230 uint64_t pd_addr);
78023016 231 void (*emit_hdp_flush)(struct amdgpu_ring *ring);
78023016
CK
232 void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
233 uint32_t gds_base, uint32_t gds_size,
234 uint32_t gws_base, uint32_t gws_size,
235 uint32_t oa_base, uint32_t oa_size);
236 /* testing functions */
237 int (*test_ring)(struct amdgpu_ring *ring);
238 int (*test_ib)(struct amdgpu_ring *ring, long timeout);
239 /* insert NOP packets */
240 void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
ef44f854 241 void (*insert_start)(struct amdgpu_ring *ring);
135d4735 242 void (*insert_end)(struct amdgpu_ring *ring);
78023016
CK
243 /* pad the indirect buffer to the necessary number of dw */
244 void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
c68cbbfd 245 unsigned (*init_cond_exec)(struct amdgpu_ring *ring, uint64_t addr);
78023016
CK
246 /* note usage for clock and power gating */
247 void (*begin_use)(struct amdgpu_ring *ring);
248 void (*end_use)(struct amdgpu_ring *ring);
249 void (*emit_switch_buffer) (struct amdgpu_ring *ring);
0bb5d5b0 250 void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
ac928705
CK
251 void (*emit_gfx_shadow)(struct amdgpu_ring *ring, u64 shadow_va, u64 csa_va,
252 u64 gds_va, bool init_shadow, int vmid);
54208194
YT
253 void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg,
254 uint32_t reg_val_offs);
b6091c12 255 void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
c1e877da
CK
256 void (*emit_reg_wait)(struct amdgpu_ring *ring, uint32_t reg,
257 uint32_t val, uint32_t mask);
82853638
AD
258 void (*emit_reg_write_reg_wait)(struct amdgpu_ring *ring,
259 uint32_t reg0, uint32_t reg1,
260 uint32_t ref, uint32_t mask);
f77c9aff
HR
261 void (*emit_frame_cntl)(struct amdgpu_ring *ring, bool start,
262 bool secure);
7876fa4f
CK
263 /* Try to soft recover the ring to make the fence signal */
264 void (*soft_recovery)(struct amdgpu_ring *ring, unsigned vmid);
692441f2 265 int (*preempt_ib)(struct amdgpu_ring *ring);
22301177 266 void (*emit_mem_sync)(struct amdgpu_ring *ring);
0a52a6ca 267 void (*emit_wave_limit)(struct amdgpu_ring *ring, bool enable);
8ff865be
JZ
268 void (*patch_cntl)(struct amdgpu_ring *ring, unsigned offset);
269 void (*patch_ce)(struct amdgpu_ring *ring, unsigned offset);
270 void (*patch_de)(struct amdgpu_ring *ring, unsigned offset);
57a372f6 271 int (*reset)(struct amdgpu_ring *ring, unsigned int vmid);
ee7a846e 272 void (*emit_cleaner_shader)(struct amdgpu_ring *ring);
4d3c4f4f 273 bool (*is_guilty)(struct amdgpu_ring *ring);
78023016
CK
274};
275
c8305c63
RS
276/**
277 * amdgpu_ring - Holds ring information
278 */
78023016
CK
279struct amdgpu_ring {
280 struct amdgpu_device *adev;
281 const struct amdgpu_ring_funcs *funcs;
282 struct amdgpu_fence_driver fence_drv;
1b1f42d8 283 struct drm_gpu_scheduler sched;
78023016
CK
284
285 struct amdgpu_bo *ring_obj;
57e92d99 286 uint32_t *ring;
78023016 287 unsigned rptr_offs;
d74c5b06
JX
288 u64 rptr_gpu_addr;
289 volatile u32 *rptr_cpu_addr;
c8305c63
RS
290
291 /**
292 * @wptr:
293 *
294 * This is part of the Ring buffer implementation and represents the
295 * write pointer. The wptr determines where the host has written.
296 */
536fbf94 297 u64 wptr;
c8305c63
RS
298
299 /**
300 * @wptr_old:
301 *
302 * Before update wptr with the new value, usually the old value is
303 * stored in the wptr_old.
304 */
536fbf94 305 u64 wptr_old;
78023016 306 unsigned ring_size;
c8305c63
RS
307
308 /**
309 * @max_dw:
310 *
311 * Maximum number of DWords for ring allocation. This information is
312 * provided at the ring initialization time, and each IP block can
313 * specify a specific value. Check places that invoke
314 * amdgpu_ring_init() to see the maximum size per block.
315 */
78023016 316 unsigned max_dw;
c8305c63
RS
317
318 /**
319 * @count_dw:
320 *
321 * This value starts with the maximum amount of DWords supported by the
322 * ring. This value is updated based on the ring manipulation.
323 */
78023016
CK
324 int count_dw;
325 uint64_t gpu_addr;
c8305c63
RS
326
327 /**
328 * @ptr_mask:
329 *
330 * Some IPs provide support for 64-bit pointers and others for 32-bit
331 * only; this behavior is component-specific and defined by the field
332 * support_64bit_ptr. If the IP block supports 64-bits, the mask
333 * 0xffffffffffffffff is set; otherwise, this value assumes buf_mask.
334 * Notice that this field is used to keep wptr under a valid range.
335 */
536fbf94 336 uint64_t ptr_mask;
c8305c63
RS
337
338 /**
339 * @buf_mask:
340 *
341 * Buffer mask is a value used to keep wptr count under its
342 * thresholding. Buffer mask initialized during the ring buffer
343 * initialization time, and it is defined as (ring_size / 4) -1.
344 */
536fbf94 345 uint32_t buf_mask;
78023016 346 u32 idx;
541372bb 347 u32 xcc_id;
797a0a14 348 u32 xcp_id;
78023016
CK
349 u32 me;
350 u32 pipe;
351 u32 queue;
352 struct amdgpu_bo *mqd_obj;
f3972b53 353 uint64_t mqd_gpu_addr;
59a82d7d 354 void *mqd_ptr;
b185c318 355 unsigned mqd_size;
34534610 356 uint64_t eop_gpu_addr;
78023016
CK
357 u32 doorbell_index;
358 bool use_doorbell;
2ffe31de 359 bool use_pollmem;
78023016 360 unsigned wptr_offs;
d74c5b06 361 u64 wptr_gpu_addr;
c8305c63
RS
362
363 /**
364 * @wptr_cpu_addr:
365 *
366 * This is the CPU address pointer in the writeback slot. This is used
367 * to commit changes to the GPU.
368 */
d74c5b06 369 volatile u32 *wptr_cpu_addr;
78023016 370 unsigned fence_offs;
d74c5b06
JX
371 u64 fence_gpu_addr;
372 volatile u32 *fence_cpu_addr;
78023016 373 uint64_t current_ctx;
78023016 374 char name[16];
ef3e1323
JX
375 u32 trail_seq;
376 unsigned trail_fence_offs;
377 u64 trail_fence_gpu_addr;
378 volatile u32 *trail_fence_cpu_addr;
78023016
CK
379 unsigned cond_exe_offs;
380 u64 cond_exe_gpu_addr;
381 volatile u32 *cond_exe_cpu_addr;
8bc75586 382 unsigned int set_q_mode_offs;
57e92d99 383 u32 *set_q_mode_ptr;
8bc75586 384 u64 set_q_mode_token;
0530553b 385 unsigned vm_hub;
4789c463 386 unsigned vm_inv_eng;
3af81440 387 struct dma_fence *vmid_wait;
dd684d31 388 bool has_compute_vm_bug;
cb3d1085 389 bool no_scheduler;
4310acd4 390 bool no_user_submission;
ebdd2e9d 391 int hw_prio;
5fd8518d
AG
392 unsigned num_hw_submission;
393 atomic_t *sched_score;
c6abbcbc 394
ded946f3
JZ
395 bool is_sw_ring;
396 unsigned int entry_index;
4d3c4f4f
J
397 /* store the cached rptr to restore after reset */
398 uint64_t cached_rptr;
78023016
CK
399};
400
cdc7893f
CK
401#define amdgpu_ring_parse_cs(r, p, job, ib) ((r)->funcs->parse_cs((p), (job), (ib)))
402#define amdgpu_ring_patch_cs_in_place(r, p, job, ib) ((r)->funcs->patch_cs_in_place((p), (job), (ib)))
0a7845db 403#define amdgpu_ring_test_ring(r) (r)->funcs->test_ring((r))
6c1a6d0b 404#define amdgpu_ring_test_ib(r, t) ((r)->funcs->test_ib ? (r)->funcs->test_ib((r), (t)) : 0)
0a7845db
HR
405#define amdgpu_ring_get_rptr(r) (r)->funcs->get_rptr((r))
406#define amdgpu_ring_get_wptr(r) (r)->funcs->get_wptr((r))
407#define amdgpu_ring_set_wptr(r) (r)->funcs->set_wptr((r))
c4c905ec 408#define amdgpu_ring_emit_ib(r, job, ib, flags) ((r)->funcs->emit_ib((r), (job), (ib), (flags)))
0a7845db
HR
409#define amdgpu_ring_emit_pipeline_sync(r) (r)->funcs->emit_pipeline_sync((r))
410#define amdgpu_ring_emit_vm_flush(r, vmid, addr) (r)->funcs->emit_vm_flush((r), (vmid), (addr))
411#define amdgpu_ring_emit_fence(r, addr, seq, flags) (r)->funcs->emit_fence((r), (addr), (seq), (flags))
412#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))
413#define amdgpu_ring_emit_hdp_flush(r) (r)->funcs->emit_hdp_flush((r))
414#define amdgpu_ring_emit_switch_buffer(r) (r)->funcs->emit_switch_buffer((r))
0bb5d5b0 415#define amdgpu_ring_emit_cntxcntl(r, d) (r)->funcs->emit_cntxcntl((r), (d))
ac928705 416#define amdgpu_ring_emit_gfx_shadow(r, s, c, g, i, v) ((r)->funcs->emit_gfx_shadow((r), (s), (c), (g), (i), (v)))
54208194 417#define amdgpu_ring_emit_rreg(r, d, o) (r)->funcs->emit_rreg((r), (d), (o))
0a7845db
HR
418#define amdgpu_ring_emit_wreg(r, d, v) (r)->funcs->emit_wreg((r), (d), (v))
419#define amdgpu_ring_emit_reg_wait(r, d, v, m) (r)->funcs->emit_reg_wait((r), (d), (v), (m))
420#define amdgpu_ring_emit_reg_write_reg_wait(r, d0, d1, v, m) (r)->funcs->emit_reg_write_reg_wait((r), (d0), (d1), (v), (m))
f77c9aff 421#define amdgpu_ring_emit_frame_cntl(r, b, s) (r)->funcs->emit_frame_cntl((r), (b), (s))
0a7845db 422#define amdgpu_ring_pad_ib(r, ib) ((r)->funcs->pad_ib((r), (ib)))
c68cbbfd 423#define amdgpu_ring_init_cond_exec(r, a) (r)->funcs->init_cond_exec((r), (a))
692441f2 424#define amdgpu_ring_preempt_ib(r) (r)->funcs->preempt_ib(r)
8ff865be
JZ
425#define amdgpu_ring_patch_cntl(r, o) ((r)->funcs->patch_cntl((r), (o)))
426#define amdgpu_ring_patch_ce(r, o) ((r)->funcs->patch_ce((r), (o)))
427#define amdgpu_ring_patch_de(r, o) ((r)->funcs->patch_de((r), (o)))
57a372f6 428#define amdgpu_ring_reset(r, v) (r)->funcs->reset((r), (v))
0a7845db 429
c30ddcec 430unsigned int amdgpu_ring_max_ibs(enum amdgpu_ring_type type);
78023016 431int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
3f4c175d
JZ
432void amdgpu_ring_ib_begin(struct amdgpu_ring *ring);
433void amdgpu_ring_ib_end(struct amdgpu_ring *ring);
8ff865be
JZ
434void amdgpu_ring_ib_on_emit_cntl(struct amdgpu_ring *ring);
435void amdgpu_ring_ib_on_emit_ce(struct amdgpu_ring *ring);
436void amdgpu_ring_ib_on_emit_de(struct amdgpu_ring *ring);
3f4c175d 437
78023016
CK
438void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
439void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
440void amdgpu_ring_commit(struct amdgpu_ring *ring);
441void amdgpu_ring_undo(struct amdgpu_ring *ring);
442int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
cf8cc382
MJ
443 unsigned int max_dw, struct amdgpu_irq_src *irq_src,
444 unsigned int irq_type, unsigned int hw_prio,
c107171b 445 atomic_t *sched_score);
78023016 446void amdgpu_ring_fini(struct amdgpu_ring *ring);
82853638
AD
447void amdgpu_ring_emit_reg_write_reg_wait_helper(struct amdgpu_ring *ring,
448 uint32_t reg0, uint32_t val0,
449 uint32_t reg1, uint32_t val1);
7876fa4f
CK
450bool amdgpu_ring_soft_recovery(struct amdgpu_ring *ring, unsigned int vmid,
451 struct dma_fence *fence);
82853638 452
dfc98479
RZ
453static inline void amdgpu_ring_set_preempt_cond_exec(struct amdgpu_ring *ring,
454 bool cond_exec)
455{
456 *ring->cond_exe_cpu_addr = cond_exec;
457}
458
c79ecfbf
ML
459static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
460{
461 int i = 0;
e09706f4 462 while (i <= ring->buf_mask)
c79ecfbf
ML
463 ring->ring[i++] = ring->funcs->nop;
464
465}
78023016 466
e8110b1c
CK
467static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
468{
e8110b1c
CK
469 ring->ring[ring->wptr++ & ring->buf_mask] = v;
470 ring->wptr &= ring->ptr_mask;
471 ring->count_dw--;
472}
473
474static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring,
475 void *src, int count_dw)
476{
477 unsigned occupied, chunk1, chunk2;
e8110b1c 478
e8110b1c 479 occupied = ring->wptr & ring->buf_mask;
e8110b1c 480 chunk1 = ring->buf_mask + 1 - occupied;
1b01c010 481 chunk1 = (chunk1 >= count_dw) ? count_dw : chunk1;
e8110b1c
CK
482 chunk2 = count_dw - chunk1;
483 chunk1 <<= 2;
484 chunk2 <<= 2;
485
486 if (chunk1)
57e92d99 487 memcpy(&ring->ring[occupied], src, chunk1);
e8110b1c
CK
488
489 if (chunk2) {
490 src += chunk1;
57e92d99 491 memcpy(ring->ring, src, chunk2);
e8110b1c
CK
492 }
493
494 ring->wptr += count_dw;
495 ring->wptr &= ring->ptr_mask;
496 ring->count_dw -= count_dw;
497}
498
c68cbbfd
CK
499/**
500 * amdgpu_ring_patch_cond_exec - patch dw count of conditional execute
501 * @ring: amdgpu_ring structure
502 * @offset: offset returned by amdgpu_ring_init_cond_exec
503 *
504 * Calculate the dw count and patch it into a cond_exec command.
505 */
506static inline void amdgpu_ring_patch_cond_exec(struct amdgpu_ring *ring,
507 unsigned int offset)
508{
509 unsigned cur;
510
511 if (!ring->funcs->init_cond_exec)
512 return;
513
514 WARN_ON(offset > ring->buf_mask);
515 WARN_ON(ring->ring[offset] != 0);
516
517 cur = (ring->wptr - 1) & ring->buf_mask;
518 if (cur < offset)
519 cur += ring->ring_size >> 2;
520 ring->ring[offset] = cur - offset;
521}
522
c66ed765
AG
523int amdgpu_ring_test_helper(struct amdgpu_ring *ring);
524
62d266b2
ND
525void amdgpu_debugfs_ring_init(struct amdgpu_device *adev,
526 struct amdgpu_ring *ring);
a190f8dc 527
80af9daa
JX
528int amdgpu_ring_init_mqd(struct amdgpu_ring *ring);
529
cdc7893f
CK
530static inline u32 amdgpu_ib_get_value(struct amdgpu_ib *ib, int idx)
531{
532 return ib->ptr[idx];
533}
534
535static inline void amdgpu_ib_set_value(struct amdgpu_ib *ib, int idx,
536 uint32_t value)
537{
538 ib->ptr[idx] = value;
539}
540
a190f8dc
CK
541int amdgpu_ib_get(struct amdgpu_device *adev, struct amdgpu_vm *vm,
542 unsigned size,
543 enum amdgpu_ib_pool_type pool,
544 struct amdgpu_ib *ib);
0014952b 545void amdgpu_ib_free(struct amdgpu_ib *ib, struct dma_fence *f);
a190f8dc
CK
546int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs,
547 struct amdgpu_ib *ibs, struct amdgpu_job *job,
548 struct dma_fence **f);
549int amdgpu_ib_pool_init(struct amdgpu_device *adev);
550void amdgpu_ib_pool_fini(struct amdgpu_device *adev);
551int amdgpu_ib_ring_tests(struct amdgpu_device *adev);
9749c868 552bool amdgpu_ring_sched_ready(struct amdgpu_ring *ring);
78023016 553#endif