0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #ifndef __AMDGPU_CTX_H__
0024 #define __AMDGPU_CTX_H__
0025
0026 #include <linux/ktime.h>
0027 #include <linux/types.h>
0028
0029 #include "amdgpu_ring.h"
0030
0031 struct drm_device;
0032 struct drm_file;
0033 struct amdgpu_fpriv;
0034 struct amdgpu_ctx_mgr;
0035
0036 #define AMDGPU_MAX_ENTITY_NUM 4
0037
0038 struct amdgpu_ctx_entity {
0039 uint32_t hw_ip;
0040 uint64_t sequence;
0041 struct drm_sched_entity entity;
0042 struct dma_fence *fences[];
0043 };
0044
0045 struct amdgpu_ctx {
0046 struct kref refcount;
0047 struct amdgpu_ctx_mgr *mgr;
0048 unsigned reset_counter;
0049 unsigned reset_counter_query;
0050 uint32_t vram_lost_counter;
0051 spinlock_t ring_lock;
0052 struct amdgpu_ctx_entity *entities[AMDGPU_HW_IP_NUM][AMDGPU_MAX_ENTITY_NUM];
0053 bool preamble_presented;
0054 int32_t init_priority;
0055 int32_t override_priority;
0056 struct mutex lock;
0057 atomic_t guilty;
0058 unsigned long ras_counter_ce;
0059 unsigned long ras_counter_ue;
0060 uint32_t stable_pstate;
0061 };
0062
0063 struct amdgpu_ctx_mgr {
0064 struct amdgpu_device *adev;
0065 struct mutex lock;
0066
0067 struct idr ctx_handles;
0068 atomic64_t time_spend[AMDGPU_HW_IP_NUM];
0069 };
0070
0071 extern const unsigned int amdgpu_ctx_num_entities[AMDGPU_HW_IP_NUM];
0072
0073 struct amdgpu_ctx *amdgpu_ctx_get(struct amdgpu_fpriv *fpriv, uint32_t id);
0074 int amdgpu_ctx_put(struct amdgpu_ctx *ctx);
0075
0076 int amdgpu_ctx_get_entity(struct amdgpu_ctx *ctx, u32 hw_ip, u32 instance,
0077 u32 ring, struct drm_sched_entity **entity);
0078 uint64_t amdgpu_ctx_add_fence(struct amdgpu_ctx *ctx,
0079 struct drm_sched_entity *entity,
0080 struct dma_fence *fence);
0081 struct dma_fence *amdgpu_ctx_get_fence(struct amdgpu_ctx *ctx,
0082 struct drm_sched_entity *entity,
0083 uint64_t seq);
0084 bool amdgpu_ctx_priority_is_valid(int32_t ctx_prio);
0085 void amdgpu_ctx_priority_override(struct amdgpu_ctx *ctx, int32_t ctx_prio);
0086
0087 int amdgpu_ctx_ioctl(struct drm_device *dev, void *data,
0088 struct drm_file *filp);
0089
0090 int amdgpu_ctx_wait_prev_fence(struct amdgpu_ctx *ctx,
0091 struct drm_sched_entity *entity);
0092
0093 void amdgpu_ctx_mgr_init(struct amdgpu_ctx_mgr *mgr,
0094 struct amdgpu_device *adev);
0095 void amdgpu_ctx_mgr_entity_fini(struct amdgpu_ctx_mgr *mgr);
0096 long amdgpu_ctx_mgr_entity_flush(struct amdgpu_ctx_mgr *mgr, long timeout);
0097 void amdgpu_ctx_mgr_fini(struct amdgpu_ctx_mgr *mgr);
0098 void amdgpu_ctx_mgr_usage(struct amdgpu_ctx_mgr *mgr,
0099 ktime_t usage[AMDGPU_HW_IP_NUM]);
0100
0101 #endif