2016-09-28 13:33:18 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Advanced Micro Devices, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Christian König
|
|
|
|
*/
|
|
|
|
#ifndef __AMDGPU_RING_H__
|
|
|
|
#define __AMDGPU_RING_H__
|
|
|
|
|
|
|
|
#include "gpu_scheduler.h"
|
|
|
|
|
|
|
|
/* max number of rings */
|
2017-01-10 16:23:23 +00:00
|
|
|
#define AMDGPU_MAX_RINGS 18
|
2016-09-28 13:33:18 +00:00
|
|
|
#define AMDGPU_MAX_GFX_RINGS 1
|
|
|
|
#define AMDGPU_MAX_COMPUTE_RINGS 8
|
|
|
|
#define AMDGPU_MAX_VCE_RINGS 3
|
2017-01-10 16:23:23 +00:00
|
|
|
#define AMDGPU_MAX_UVD_ENC_RINGS 2
|
2016-09-28 13:33:18 +00:00
|
|
|
|
|
|
|
/* some special values for the owner field */
|
|
|
|
#define AMDGPU_FENCE_OWNER_UNDEFINED ((void*)0ul)
|
|
|
|
#define AMDGPU_FENCE_OWNER_VM ((void*)1ul)
|
|
|
|
|
|
|
|
#define AMDGPU_FENCE_FLAG_64BIT (1 << 0)
|
|
|
|
#define AMDGPU_FENCE_FLAG_INT (1 << 1)
|
|
|
|
|
|
|
|
enum amdgpu_ring_type {
|
|
|
|
AMDGPU_RING_TYPE_GFX,
|
|
|
|
AMDGPU_RING_TYPE_COMPUTE,
|
|
|
|
AMDGPU_RING_TYPE_SDMA,
|
|
|
|
AMDGPU_RING_TYPE_UVD,
|
2016-10-31 06:51:18 +00:00
|
|
|
AMDGPU_RING_TYPE_VCE,
|
2017-01-12 18:19:46 +00:00
|
|
|
AMDGPU_RING_TYPE_KIQ,
|
2017-05-05 15:40:59 +00:00
|
|
|
AMDGPU_RING_TYPE_UVD_ENC,
|
|
|
|
AMDGPU_RING_TYPE_VCN_DEC
|
2016-09-28 13:33:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct amdgpu_device;
|
|
|
|
struct amdgpu_ring;
|
|
|
|
struct amdgpu_ib;
|
|
|
|
struct amdgpu_cs_parser;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fences.
|
|
|
|
*/
|
|
|
|
struct amdgpu_fence_driver {
|
|
|
|
uint64_t gpu_addr;
|
|
|
|
volatile uint32_t *cpu_addr;
|
|
|
|
/* sync_seq is protected by ring emission lock */
|
|
|
|
uint32_t sync_seq;
|
|
|
|
atomic_t last_seq;
|
|
|
|
bool initialized;
|
|
|
|
struct amdgpu_irq_src *irq_src;
|
|
|
|
unsigned irq_type;
|
|
|
|
struct timer_list fallback_timer;
|
|
|
|
unsigned num_fences_mask;
|
|
|
|
spinlock_t lock;
|
2016-10-28 01:33:52 +00:00
|
|
|
struct dma_fence **fences;
|
2016-09-28 13:33:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int amdgpu_fence_driver_init(struct amdgpu_device *adev);
|
|
|
|
void amdgpu_fence_driver_fini(struct amdgpu_device *adev);
|
|
|
|
void amdgpu_fence_driver_force_completion(struct amdgpu_device *adev);
|
drm/amdgpu/SRIOV:implement guilty job TDR for(V2)
1,TDR will kickout guilty job if it hang exceed the threshold
of the given one from kernel paramter "job_hang_limit", that
way a bad command stream will not infinitly cause GPU hang.
by default this threshold is 1 so a job will be kicked out
after it hang.
2,if a job timeout TDR routine will not reset all sched/ring,
instead if will only reset on the givn one which is indicated
by @job of amdgpu_sriov_gpu_reset, that way we don't need to
reset and recover each sched/ring if we already know which job
cause GPU hang.
3,unblock sriov_gpu_reset for AI family.
V2:
1:put kickout guilty job after sched parked.
2:since parking scheduler prior to kickout already occupies a
while, we can do last check on the in question job before
doing hw_reset.
TODO:
1:when a job is considered as guilty, we should mark some flag
in its fence status flag, and let UMD side aware that this
fence signaling is not due to job complete but job hang.
2:if gpu reset cause all video memory lost, we need introduce
a new policy to implement TDR, like drop all jobs not yet
signaled, and all IOCTL on this device will return ERROR
DEVICE_LOST.
this will be implemented later.
Signed-off-by: Monk Liu <Monk.Liu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
2017-05-11 05:36:44 +00:00
|
|
|
void amdgpu_fence_driver_force_completion_ring(struct amdgpu_ring *ring);
|
2016-09-28 13:33:18 +00:00
|
|
|
|
|
|
|
int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
|
|
|
|
unsigned num_hw_submission);
|
|
|
|
int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
|
|
|
|
struct amdgpu_irq_src *irq_src,
|
|
|
|
unsigned irq_type);
|
|
|
|
void amdgpu_fence_driver_suspend(struct amdgpu_device *adev);
|
|
|
|
void amdgpu_fence_driver_resume(struct amdgpu_device *adev);
|
2016-10-28 01:33:52 +00:00
|
|
|
int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **fence);
|
2016-09-28 13:33:18 +00:00
|
|
|
void amdgpu_fence_process(struct amdgpu_ring *ring);
|
|
|
|
int amdgpu_fence_wait_empty(struct amdgpu_ring *ring);
|
|
|
|
unsigned amdgpu_fence_count_emitted(struct amdgpu_ring *ring);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rings.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* provided by hw blocks that expose a ring buffer for commands */
|
|
|
|
struct amdgpu_ring_funcs {
|
2016-10-05 13:36:39 +00:00
|
|
|
enum amdgpu_ring_type type;
|
2016-10-05 14:09:32 +00:00
|
|
|
uint32_t align_mask;
|
|
|
|
u32 nop;
|
2016-03-12 01:32:30 +00:00
|
|
|
bool support_64bit_ptrs;
|
2017-03-30 12:49:50 +00:00
|
|
|
unsigned vmhub;
|
2016-10-05 13:36:39 +00:00
|
|
|
|
2016-09-28 13:33:18 +00:00
|
|
|
/* ring read/write ptr handling */
|
2016-03-12 01:32:30 +00:00
|
|
|
u64 (*get_rptr)(struct amdgpu_ring *ring);
|
|
|
|
u64 (*get_wptr)(struct amdgpu_ring *ring);
|
2016-09-28 13:33:18 +00:00
|
|
|
void (*set_wptr)(struct amdgpu_ring *ring);
|
|
|
|
/* validating and patching of IBs */
|
|
|
|
int (*parse_cs)(struct amdgpu_cs_parser *p, uint32_t ib_idx);
|
2016-10-05 12:29:38 +00:00
|
|
|
/* constants to calculate how many DW are needed for an emit */
|
|
|
|
unsigned emit_frame_size;
|
|
|
|
unsigned emit_ib_size;
|
2016-09-28 13:33:18 +00:00
|
|
|
/* command emit functions */
|
|
|
|
void (*emit_ib)(struct amdgpu_ring *ring,
|
|
|
|
struct amdgpu_ib *ib,
|
|
|
|
unsigned vm_id, bool ctx_switch);
|
|
|
|
void (*emit_fence)(struct amdgpu_ring *ring, uint64_t addr,
|
|
|
|
uint64_t seq, unsigned flags);
|
|
|
|
void (*emit_pipeline_sync)(struct amdgpu_ring *ring);
|
|
|
|
void (*emit_vm_flush)(struct amdgpu_ring *ring, unsigned vm_id,
|
|
|
|
uint64_t pd_addr);
|
|
|
|
void (*emit_hdp_flush)(struct amdgpu_ring *ring);
|
|
|
|
void (*emit_hdp_invalidate)(struct amdgpu_ring *ring);
|
|
|
|
void (*emit_gds_switch)(struct amdgpu_ring *ring, uint32_t vmid,
|
|
|
|
uint32_t gds_base, uint32_t gds_size,
|
|
|
|
uint32_t gws_base, uint32_t gws_size,
|
|
|
|
uint32_t oa_base, uint32_t oa_size);
|
|
|
|
/* testing functions */
|
|
|
|
int (*test_ring)(struct amdgpu_ring *ring);
|
|
|
|
int (*test_ib)(struct amdgpu_ring *ring, long timeout);
|
|
|
|
/* insert NOP packets */
|
|
|
|
void (*insert_nop)(struct amdgpu_ring *ring, uint32_t count);
|
2017-05-11 20:29:08 +00:00
|
|
|
void (*insert_start)(struct amdgpu_ring *ring);
|
2016-12-14 20:05:00 +00:00
|
|
|
void (*insert_end)(struct amdgpu_ring *ring);
|
2016-09-28 13:33:18 +00:00
|
|
|
/* pad the indirect buffer to the necessary number of dw */
|
|
|
|
void (*pad_ib)(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
|
|
|
|
unsigned (*init_cond_exec)(struct amdgpu_ring *ring);
|
|
|
|
void (*patch_cond_exec)(struct amdgpu_ring *ring, unsigned offset);
|
|
|
|
/* note usage for clock and power gating */
|
|
|
|
void (*begin_use)(struct amdgpu_ring *ring);
|
|
|
|
void (*end_use)(struct amdgpu_ring *ring);
|
|
|
|
void (*emit_switch_buffer) (struct amdgpu_ring *ring);
|
|
|
|
void (*emit_cntxcntl) (struct amdgpu_ring *ring, uint32_t flags);
|
2017-01-10 04:53:52 +00:00
|
|
|
void (*emit_rreg)(struct amdgpu_ring *ring, uint32_t reg);
|
|
|
|
void (*emit_wreg)(struct amdgpu_ring *ring, uint32_t reg, uint32_t val);
|
2017-05-01 10:09:22 +00:00
|
|
|
void (*emit_tmz)(struct amdgpu_ring *ring, bool start);
|
2016-09-28 13:33:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct amdgpu_ring {
|
|
|
|
struct amdgpu_device *adev;
|
|
|
|
const struct amdgpu_ring_funcs *funcs;
|
|
|
|
struct amdgpu_fence_driver fence_drv;
|
|
|
|
struct amd_gpu_scheduler sched;
|
|
|
|
|
|
|
|
struct amdgpu_bo *ring_obj;
|
|
|
|
volatile uint32_t *ring;
|
|
|
|
unsigned rptr_offs;
|
2016-03-12 01:32:30 +00:00
|
|
|
u64 wptr;
|
|
|
|
u64 wptr_old;
|
2016-09-28 13:33:18 +00:00
|
|
|
unsigned ring_size;
|
|
|
|
unsigned max_dw;
|
|
|
|
int count_dw;
|
|
|
|
uint64_t gpu_addr;
|
2016-03-12 01:32:30 +00:00
|
|
|
uint64_t ptr_mask;
|
|
|
|
uint32_t buf_mask;
|
2016-09-28 13:33:18 +00:00
|
|
|
bool ready;
|
|
|
|
u32 idx;
|
|
|
|
u32 me;
|
|
|
|
u32 pipe;
|
|
|
|
u32 queue;
|
|
|
|
struct amdgpu_bo *mqd_obj;
|
2017-01-24 10:33:22 +00:00
|
|
|
uint64_t mqd_gpu_addr;
|
2017-02-17 08:03:10 +00:00
|
|
|
void *mqd_ptr;
|
2017-03-23 06:16:07 +00:00
|
|
|
uint64_t eop_gpu_addr;
|
2016-09-28 13:33:18 +00:00
|
|
|
u32 doorbell_index;
|
|
|
|
bool use_doorbell;
|
|
|
|
unsigned wptr_offs;
|
|
|
|
unsigned fence_offs;
|
|
|
|
uint64_t current_ctx;
|
|
|
|
char name[16];
|
|
|
|
unsigned cond_exe_offs;
|
|
|
|
u64 cond_exe_gpu_addr;
|
|
|
|
volatile u32 *cond_exe_cpu_addr;
|
2017-03-31 09:03:50 +00:00
|
|
|
unsigned vm_inv_eng;
|
2016-09-28 13:33:18 +00:00
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
|
|
struct dentry *ent;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
int amdgpu_ring_alloc(struct amdgpu_ring *ring, unsigned ndw);
|
|
|
|
void amdgpu_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count);
|
|
|
|
void amdgpu_ring_generic_pad_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib);
|
|
|
|
void amdgpu_ring_commit(struct amdgpu_ring *ring);
|
|
|
|
void amdgpu_ring_undo(struct amdgpu_ring *ring);
|
|
|
|
int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
|
2016-10-05 14:09:32 +00:00
|
|
|
unsigned ring_size, struct amdgpu_irq_src *irq_src,
|
|
|
|
unsigned irq_type);
|
2016-09-28 13:33:18 +00:00
|
|
|
void amdgpu_ring_fini(struct amdgpu_ring *ring);
|
2017-02-08 08:49:46 +00:00
|
|
|
static inline void amdgpu_ring_clear_ring(struct amdgpu_ring *ring)
|
|
|
|
{
|
|
|
|
int i = 0;
|
2017-03-21 10:48:45 +00:00
|
|
|
while (i <= ring->buf_mask)
|
2017-02-08 08:49:46 +00:00
|
|
|
ring->ring[i++] = ring->funcs->nop;
|
|
|
|
|
|
|
|
}
|
2016-09-28 13:33:18 +00:00
|
|
|
|
|
|
|
#endif
|