xref: /linux/drivers/gpu/drm/xe/xe_lrc.h (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
1dd08ebf6SMatthew Brost /* SPDX-License-Identifier: MIT */
2dd08ebf6SMatthew Brost /*
3dd08ebf6SMatthew Brost  * Copyright © 2021 Intel Corporation
4dd08ebf6SMatthew Brost  */
5dd08ebf6SMatthew Brost #ifndef _XE_LRC_H_
6dd08ebf6SMatthew Brost #define _XE_LRC_H_
7dd08ebf6SMatthew Brost 
838830bfeSMichal Wajdeczko #include <linux/types.h>
9dd08ebf6SMatthew Brost 
10264eecdbSNiranjana Vishwanathapura #include "xe_lrc_types.h"
11264eecdbSNiranjana Vishwanathapura 
120f60547fSMatt Roper struct drm_printer;
13b1543a49SMatt Roper struct xe_bb;
14dd08ebf6SMatthew Brost struct xe_device;
159b9529ceSFrancois Dugast struct xe_exec_queue;
16dd08ebf6SMatthew Brost enum xe_engine_class;
1738830bfeSMichal Wajdeczko struct xe_gt;
18dd08ebf6SMatthew Brost struct xe_hw_engine;
1938830bfeSMichal Wajdeczko struct xe_lrc;
20dd08ebf6SMatthew Brost struct xe_vm;
21dd08ebf6SMatthew Brost 
22ecb63364SZhanjun Dong struct xe_lrc_snapshot {
23ecb63364SZhanjun Dong 	struct xe_bo *lrc_bo;
24ecb63364SZhanjun Dong 	void *lrc_snapshot;
25ecb63364SZhanjun Dong 	unsigned long lrc_size, lrc_offset;
26ecb63364SZhanjun Dong 
27ecb63364SZhanjun Dong 	u32 context_desc;
2837aa19faSMatthew Brost 	u32 ring_addr;
29ecb63364SZhanjun Dong 	u32 indirect_context_desc;
30ecb63364SZhanjun Dong 	u32 head;
319a1fce9dSMatthew Brost 	u32 start;
32ecb63364SZhanjun Dong 	struct {
33ecb63364SZhanjun Dong 		u32 internal;
34ecb63364SZhanjun Dong 		u32 memory;
35ecb63364SZhanjun Dong 	} tail;
36ecb63364SZhanjun Dong 	u32 start_seqno;
37ecb63364SZhanjun Dong 	u32 seqno;
38ecb63364SZhanjun Dong 	u32 ctx_timestamp;
39ecb63364SZhanjun Dong 	u32 ctx_job_timestamp;
40ecb63364SZhanjun Dong };
41ecb63364SZhanjun Dong 
42f0c06677SDaniele Ceraolo Spurio #define LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR (0x34 * 4)
43f0c06677SDaniele Ceraolo Spurio #define LRC_PPHWSP_PXP_INVAL_SCRATCH_ADDR (0x40 * 4)
44dd08ebf6SMatthew Brost 
4572d47960SDaniele Ceraolo Spurio #define XE_LRC_CREATE_RUNALONE 0x1
4672d47960SDaniele Ceraolo Spurio #define XE_LRC_CREATE_PXP 0x2
47264eecdbSNiranjana Vishwanathapura struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
4872d47960SDaniele Ceraolo Spurio 			     u32 ring_size, u16 msix_vec, u32 flags);
49264eecdbSNiranjana Vishwanathapura void xe_lrc_destroy(struct kref *ref);
50264eecdbSNiranjana Vishwanathapura 
51877517f2SNiranjana Vishwanathapura /**
52877517f2SNiranjana Vishwanathapura  * xe_lrc_get - Get reference to the LRC
53877517f2SNiranjana Vishwanathapura  * @lrc: Logical Ring Context
54877517f2SNiranjana Vishwanathapura  *
55877517f2SNiranjana Vishwanathapura  * Increment reference count of @lrc
56877517f2SNiranjana Vishwanathapura  */
xe_lrc_get(struct xe_lrc * lrc)57264eecdbSNiranjana Vishwanathapura static inline struct xe_lrc *xe_lrc_get(struct xe_lrc *lrc)
58264eecdbSNiranjana Vishwanathapura {
59264eecdbSNiranjana Vishwanathapura 	kref_get(&lrc->refcount);
60264eecdbSNiranjana Vishwanathapura 	return lrc;
61264eecdbSNiranjana Vishwanathapura }
62264eecdbSNiranjana Vishwanathapura 
63877517f2SNiranjana Vishwanathapura /**
64877517f2SNiranjana Vishwanathapura  * xe_lrc_put - Put reference of the LRC
65877517f2SNiranjana Vishwanathapura  * @lrc: Logical Ring Context
66877517f2SNiranjana Vishwanathapura  *
67877517f2SNiranjana Vishwanathapura  * Decrement reference count of @lrc, call xe_lrc_destroy when
68877517f2SNiranjana Vishwanathapura  * reference count reaches 0.
69877517f2SNiranjana Vishwanathapura  */
xe_lrc_put(struct xe_lrc * lrc)70264eecdbSNiranjana Vishwanathapura static inline void xe_lrc_put(struct xe_lrc *lrc)
71264eecdbSNiranjana Vishwanathapura {
72264eecdbSNiranjana Vishwanathapura 	kref_put(&lrc->refcount, xe_lrc_destroy);
73264eecdbSNiranjana Vishwanathapura }
74dd08ebf6SMatthew Brost 
75d6219e1cSNiranjana Vishwanathapura size_t xe_gt_lrc_size(struct xe_gt *gt, enum xe_engine_class class);
76dd08ebf6SMatthew Brost u32 xe_lrc_pphwsp_offset(struct xe_lrc *lrc);
772f4a730fSAshutosh Dixit u32 xe_lrc_regs_offset(struct xe_lrc *lrc);
78dd08ebf6SMatthew Brost 
79d6219e1cSNiranjana Vishwanathapura void xe_lrc_set_ring_tail(struct xe_lrc *lrc, u32 tail);
80d6219e1cSNiranjana Vishwanathapura u32 xe_lrc_ring_tail(struct xe_lrc *lrc);
81dd08ebf6SMatthew Brost void xe_lrc_set_ring_head(struct xe_lrc *lrc, u32 head);
82dd08ebf6SMatthew Brost u32 xe_lrc_ring_head(struct xe_lrc *lrc);
83dd08ebf6SMatthew Brost u32 xe_lrc_ring_space(struct xe_lrc *lrc);
84dd08ebf6SMatthew Brost void xe_lrc_write_ring(struct xe_lrc *lrc, const void *data, size_t size);
85dd08ebf6SMatthew Brost 
8610304796SMatthew Brost bool xe_lrc_ring_is_idle(struct xe_lrc *lrc);
8710304796SMatthew Brost 
88d6219e1cSNiranjana Vishwanathapura u32 xe_lrc_indirect_ring_ggtt_addr(struct xe_lrc *lrc);
89dd08ebf6SMatthew Brost u32 xe_lrc_ggtt_addr(struct xe_lrc *lrc);
90dd08ebf6SMatthew Brost u32 *xe_lrc_regs(struct xe_lrc *lrc);
91dd08ebf6SMatthew Brost 
92dd08ebf6SMatthew Brost u32 xe_lrc_read_ctx_reg(struct xe_lrc *lrc, int reg_nr);
93dd08ebf6SMatthew Brost void xe_lrc_write_ctx_reg(struct xe_lrc *lrc, int reg_nr, u32 val);
94dd08ebf6SMatthew Brost 
95dd08ebf6SMatthew Brost u64 xe_lrc_descriptor(struct xe_lrc *lrc);
96dd08ebf6SMatthew Brost 
97dd08ebf6SMatthew Brost u32 xe_lrc_seqno_ggtt_addr(struct xe_lrc *lrc);
98e183910aSThomas Hellström struct dma_fence *xe_lrc_alloc_seqno_fence(void);
99e183910aSThomas Hellström void xe_lrc_free_seqno_fence(struct dma_fence *fence);
100e183910aSThomas Hellström void xe_lrc_init_seqno_fence(struct xe_lrc *lrc, struct dma_fence *fence);
101dd08ebf6SMatthew Brost s32 xe_lrc_seqno(struct xe_lrc *lrc);
102dd08ebf6SMatthew Brost 
103dd08ebf6SMatthew Brost u32 xe_lrc_start_seqno_ggtt_addr(struct xe_lrc *lrc);
104dd08ebf6SMatthew Brost s32 xe_lrc_start_seqno(struct xe_lrc *lrc);
105dd08ebf6SMatthew Brost 
106dd08ebf6SMatthew Brost u32 xe_lrc_parallel_ggtt_addr(struct xe_lrc *lrc);
107dd08ebf6SMatthew Brost struct iosys_map xe_lrc_parallel_map(struct xe_lrc *lrc);
108dd08ebf6SMatthew Brost 
109dd08ebf6SMatthew Brost size_t xe_lrc_skip_size(struct xe_device *xe);
110dd08ebf6SMatthew Brost 
1110f60547fSMatt Roper void xe_lrc_dump_default(struct drm_printer *p,
1120f60547fSMatt Roper 			 struct xe_gt *gt,
1130f60547fSMatt Roper 			 enum xe_engine_class);
1140f60547fSMatt Roper 
115b1543a49SMatt Roper u32 *xe_lrc_emit_hwe_state_instructions(struct xe_exec_queue *q, u32 *cs);
116b1543a49SMatt Roper 
11747058633SMaarten Lankhorst struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc);
118784b3410SMaarten Lankhorst void xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot);
11947058633SMaarten Lankhorst void xe_lrc_snapshot_print(struct xe_lrc_snapshot *snapshot, struct drm_printer *p);
12047058633SMaarten Lankhorst void xe_lrc_snapshot_free(struct xe_lrc_snapshot *snapshot);
12147058633SMaarten Lankhorst 
1228b9544e0SMatthew Brost u32 xe_lrc_ctx_timestamp_ggtt_addr(struct xe_lrc *lrc);
123*617d824cSUmesh Nerlige Ramappa u32 xe_lrc_ctx_timestamp_udw_ggtt_addr(struct xe_lrc *lrc);
124*617d824cSUmesh Nerlige Ramappa u64 xe_lrc_ctx_timestamp(struct xe_lrc *lrc);
1258b9544e0SMatthew Brost u32 xe_lrc_ctx_job_timestamp_ggtt_addr(struct xe_lrc *lrc);
1268b9544e0SMatthew Brost u32 xe_lrc_ctx_job_timestamp(struct xe_lrc *lrc);
1278b9544e0SMatthew Brost 
1289b090d57SUmesh Nerlige Ramappa /**
1299b090d57SUmesh Nerlige Ramappa  * xe_lrc_update_timestamp - readout LRC timestamp and update cached value
1309b090d57SUmesh Nerlige Ramappa  * @lrc: logical ring context for this exec queue
1319b090d57SUmesh Nerlige Ramappa  * @old_ts: pointer where to save the previous timestamp
1329b090d57SUmesh Nerlige Ramappa  *
1339b090d57SUmesh Nerlige Ramappa  * Read the current timestamp for this LRC and update the cached value. The
1349b090d57SUmesh Nerlige Ramappa  * previous cached value is also returned in @old_ts so the caller can calculate
1359b090d57SUmesh Nerlige Ramappa  * the delta between 2 updates. Note that this is not intended to be called from
1369b090d57SUmesh Nerlige Ramappa  * any place, but just by the paths updating the drm client utilization.
1379b090d57SUmesh Nerlige Ramappa  *
1389b090d57SUmesh Nerlige Ramappa  * Returns the current LRC timestamp
1399b090d57SUmesh Nerlige Ramappa  */
140*617d824cSUmesh Nerlige Ramappa u64 xe_lrc_update_timestamp(struct xe_lrc *lrc, u64 *old_ts);
1419b090d57SUmesh Nerlige Ramappa 
142dd08ebf6SMatthew Brost #endif
143