xref: /linux/drivers/gpu/drm/xe/xe_lrc.h (revision f0c06677d1105a599370ffd0c94679996c3656f2)
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 
42*f0c06677SDaniele Ceraolo Spurio #define LRC_PPHWSP_FLUSH_INVAL_SCRATCH_ADDR (0x34 * 4)
43*f0c06677SDaniele Ceraolo Spurio #define LRC_PPHWSP_PXP_INVAL_SCRATCH_ADDR (0x40 * 4)
44dd08ebf6SMatthew Brost 
45264eecdbSNiranjana Vishwanathapura struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
4621d07f5fSIlia Levi 			     u32 ring_size, u16 msix_vec);
47264eecdbSNiranjana Vishwanathapura void xe_lrc_destroy(struct kref *ref);
48264eecdbSNiranjana Vishwanathapura 
49877517f2SNiranjana Vishwanathapura /**
50877517f2SNiranjana Vishwanathapura  * xe_lrc_get - Get reference to the LRC
51877517f2SNiranjana Vishwanathapura  * @lrc: Logical Ring Context
52877517f2SNiranjana Vishwanathapura  *
53877517f2SNiranjana Vishwanathapura  * Increment reference count of @lrc
54877517f2SNiranjana Vishwanathapura  */
55264eecdbSNiranjana Vishwanathapura static inline struct xe_lrc *xe_lrc_get(struct xe_lrc *lrc)
56264eecdbSNiranjana Vishwanathapura {
57264eecdbSNiranjana Vishwanathapura 	kref_get(&lrc->refcount);
58264eecdbSNiranjana Vishwanathapura 	return lrc;
59264eecdbSNiranjana Vishwanathapura }
60264eecdbSNiranjana Vishwanathapura 
61877517f2SNiranjana Vishwanathapura /**
62877517f2SNiranjana Vishwanathapura  * xe_lrc_put - Put reference of the LRC
63877517f2SNiranjana Vishwanathapura  * @lrc: Logical Ring Context
64877517f2SNiranjana Vishwanathapura  *
65877517f2SNiranjana Vishwanathapura  * Decrement reference count of @lrc, call xe_lrc_destroy when
66877517f2SNiranjana Vishwanathapura  * reference count reaches 0.
67877517f2SNiranjana Vishwanathapura  */
68264eecdbSNiranjana Vishwanathapura static inline void xe_lrc_put(struct xe_lrc *lrc)
69264eecdbSNiranjana Vishwanathapura {
70264eecdbSNiranjana Vishwanathapura 	kref_put(&lrc->refcount, xe_lrc_destroy);
71264eecdbSNiranjana Vishwanathapura }
72dd08ebf6SMatthew Brost 
73d6219e1cSNiranjana Vishwanathapura size_t xe_gt_lrc_size(struct xe_gt *gt, enum xe_engine_class class);
74dd08ebf6SMatthew Brost u32 xe_lrc_pphwsp_offset(struct xe_lrc *lrc);
752f4a730fSAshutosh Dixit u32 xe_lrc_regs_offset(struct xe_lrc *lrc);
76dd08ebf6SMatthew Brost 
77d6219e1cSNiranjana Vishwanathapura void xe_lrc_set_ring_tail(struct xe_lrc *lrc, u32 tail);
78d6219e1cSNiranjana Vishwanathapura u32 xe_lrc_ring_tail(struct xe_lrc *lrc);
79dd08ebf6SMatthew Brost void xe_lrc_set_ring_head(struct xe_lrc *lrc, u32 head);
80dd08ebf6SMatthew Brost u32 xe_lrc_ring_head(struct xe_lrc *lrc);
81dd08ebf6SMatthew Brost u32 xe_lrc_ring_space(struct xe_lrc *lrc);
82dd08ebf6SMatthew Brost void xe_lrc_write_ring(struct xe_lrc *lrc, const void *data, size_t size);
83dd08ebf6SMatthew Brost 
8410304796SMatthew Brost bool xe_lrc_ring_is_idle(struct xe_lrc *lrc);
8510304796SMatthew Brost 
86d6219e1cSNiranjana Vishwanathapura u32 xe_lrc_indirect_ring_ggtt_addr(struct xe_lrc *lrc);
87dd08ebf6SMatthew Brost u32 xe_lrc_ggtt_addr(struct xe_lrc *lrc);
88dd08ebf6SMatthew Brost u32 *xe_lrc_regs(struct xe_lrc *lrc);
89dd08ebf6SMatthew Brost 
90dd08ebf6SMatthew Brost u32 xe_lrc_read_ctx_reg(struct xe_lrc *lrc, int reg_nr);
91dd08ebf6SMatthew Brost void xe_lrc_write_ctx_reg(struct xe_lrc *lrc, int reg_nr, u32 val);
92dd08ebf6SMatthew Brost 
93dd08ebf6SMatthew Brost u64 xe_lrc_descriptor(struct xe_lrc *lrc);
94dd08ebf6SMatthew Brost 
95dd08ebf6SMatthew Brost u32 xe_lrc_seqno_ggtt_addr(struct xe_lrc *lrc);
96e183910aSThomas Hellström struct dma_fence *xe_lrc_alloc_seqno_fence(void);
97e183910aSThomas Hellström void xe_lrc_free_seqno_fence(struct dma_fence *fence);
98e183910aSThomas Hellström void xe_lrc_init_seqno_fence(struct xe_lrc *lrc, struct dma_fence *fence);
99dd08ebf6SMatthew Brost s32 xe_lrc_seqno(struct xe_lrc *lrc);
100dd08ebf6SMatthew Brost 
101dd08ebf6SMatthew Brost u32 xe_lrc_start_seqno_ggtt_addr(struct xe_lrc *lrc);
102dd08ebf6SMatthew Brost s32 xe_lrc_start_seqno(struct xe_lrc *lrc);
103dd08ebf6SMatthew Brost 
104dd08ebf6SMatthew Brost u32 xe_lrc_parallel_ggtt_addr(struct xe_lrc *lrc);
105dd08ebf6SMatthew Brost struct iosys_map xe_lrc_parallel_map(struct xe_lrc *lrc);
106dd08ebf6SMatthew Brost 
107dd08ebf6SMatthew Brost size_t xe_lrc_skip_size(struct xe_device *xe);
108dd08ebf6SMatthew Brost 
1090f60547fSMatt Roper void xe_lrc_dump_default(struct drm_printer *p,
1100f60547fSMatt Roper 			 struct xe_gt *gt,
1110f60547fSMatt Roper 			 enum xe_engine_class);
1120f60547fSMatt Roper 
113b1543a49SMatt Roper void xe_lrc_emit_hwe_state_instructions(struct xe_exec_queue *q, struct xe_bb *bb);
114b1543a49SMatt Roper 
11547058633SMaarten Lankhorst struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc);
116784b3410SMaarten Lankhorst void xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot);
11747058633SMaarten Lankhorst void xe_lrc_snapshot_print(struct xe_lrc_snapshot *snapshot, struct drm_printer *p);
11847058633SMaarten Lankhorst void xe_lrc_snapshot_free(struct xe_lrc_snapshot *snapshot);
11947058633SMaarten Lankhorst 
1208b9544e0SMatthew Brost u32 xe_lrc_ctx_timestamp_ggtt_addr(struct xe_lrc *lrc);
1218b9544e0SMatthew Brost u32 xe_lrc_ctx_timestamp(struct xe_lrc *lrc);
1228b9544e0SMatthew Brost u32 xe_lrc_ctx_job_timestamp_ggtt_addr(struct xe_lrc *lrc);
1238b9544e0SMatthew Brost u32 xe_lrc_ctx_job_timestamp(struct xe_lrc *lrc);
1248b9544e0SMatthew Brost 
1259b090d57SUmesh Nerlige Ramappa /**
1269b090d57SUmesh Nerlige Ramappa  * xe_lrc_update_timestamp - readout LRC timestamp and update cached value
1279b090d57SUmesh Nerlige Ramappa  * @lrc: logical ring context for this exec queue
1289b090d57SUmesh Nerlige Ramappa  * @old_ts: pointer where to save the previous timestamp
1299b090d57SUmesh Nerlige Ramappa  *
1309b090d57SUmesh Nerlige Ramappa  * Read the current timestamp for this LRC and update the cached value. The
1319b090d57SUmesh Nerlige Ramappa  * previous cached value is also returned in @old_ts so the caller can calculate
1329b090d57SUmesh Nerlige Ramappa  * the delta between 2 updates. Note that this is not intended to be called from
1339b090d57SUmesh Nerlige Ramappa  * any place, but just by the paths updating the drm client utilization.
1349b090d57SUmesh Nerlige Ramappa  *
1359b090d57SUmesh Nerlige Ramappa  * Returns the current LRC timestamp
1369b090d57SUmesh Nerlige Ramappa  */
1379b090d57SUmesh Nerlige Ramappa u32 xe_lrc_update_timestamp(struct xe_lrc *lrc, u32 *old_ts);
1389b090d57SUmesh Nerlige Ramappa 
139dd08ebf6SMatthew Brost #endif
140