1 /* SPDX-License-Identifier: MIT */
2 /*
3 * Copyright © 2021 Intel Corporation
4 */
5 #ifndef _XE_LRC_H_
6 #define _XE_LRC_H_
7
8 #include <linux/types.h>
9
10 #include "xe_lrc_types.h"
11
12 struct drm_printer;
13 struct xe_bb;
14 struct xe_device;
15 struct xe_exec_queue;
16 enum xe_engine_class;
17 struct xe_gt;
18 struct xe_hw_engine;
19 struct xe_lrc;
20 struct xe_lrc_snapshot;
21 struct xe_vm;
22
23 #define LRC_PPHWSP_SCRATCH_ADDR (0x34 * 4)
24
25 struct xe_lrc *xe_lrc_create(struct xe_hw_engine *hwe, struct xe_vm *vm,
26 u32 ring_size);
27 void xe_lrc_destroy(struct kref *ref);
28
29 /**
30 * xe_lrc_get - Get reference to the LRC
31 * @lrc: Logical Ring Context
32 *
33 * Increment reference count of @lrc
34 */
xe_lrc_get(struct xe_lrc * lrc)35 static inline struct xe_lrc *xe_lrc_get(struct xe_lrc *lrc)
36 {
37 kref_get(&lrc->refcount);
38 return lrc;
39 }
40
41 /**
42 * xe_lrc_put - Put reference of the LRC
43 * @lrc: Logical Ring Context
44 *
45 * Decrement reference count of @lrc, call xe_lrc_destroy when
46 * reference count reaches 0.
47 */
xe_lrc_put(struct xe_lrc * lrc)48 static inline void xe_lrc_put(struct xe_lrc *lrc)
49 {
50 kref_put(&lrc->refcount, xe_lrc_destroy);
51 }
52
53 size_t xe_gt_lrc_size(struct xe_gt *gt, enum xe_engine_class class);
54 u32 xe_lrc_pphwsp_offset(struct xe_lrc *lrc);
55 u32 xe_lrc_regs_offset(struct xe_lrc *lrc);
56
57 void xe_lrc_set_ring_tail(struct xe_lrc *lrc, u32 tail);
58 u32 xe_lrc_ring_tail(struct xe_lrc *lrc);
59 void xe_lrc_set_ring_head(struct xe_lrc *lrc, u32 head);
60 u32 xe_lrc_ring_head(struct xe_lrc *lrc);
61 u32 xe_lrc_ring_space(struct xe_lrc *lrc);
62 void xe_lrc_write_ring(struct xe_lrc *lrc, const void *data, size_t size);
63
64 u32 xe_lrc_indirect_ring_ggtt_addr(struct xe_lrc *lrc);
65 u32 xe_lrc_ggtt_addr(struct xe_lrc *lrc);
66 u32 *xe_lrc_regs(struct xe_lrc *lrc);
67
68 u32 xe_lrc_read_ctx_reg(struct xe_lrc *lrc, int reg_nr);
69 void xe_lrc_write_ctx_reg(struct xe_lrc *lrc, int reg_nr, u32 val);
70
71 u64 xe_lrc_descriptor(struct xe_lrc *lrc);
72
73 u32 xe_lrc_seqno_ggtt_addr(struct xe_lrc *lrc);
74 struct dma_fence *xe_lrc_alloc_seqno_fence(void);
75 void xe_lrc_free_seqno_fence(struct dma_fence *fence);
76 void xe_lrc_init_seqno_fence(struct xe_lrc *lrc, struct dma_fence *fence);
77 s32 xe_lrc_seqno(struct xe_lrc *lrc);
78
79 u32 xe_lrc_start_seqno_ggtt_addr(struct xe_lrc *lrc);
80 s32 xe_lrc_start_seqno(struct xe_lrc *lrc);
81
82 u32 xe_lrc_parallel_ggtt_addr(struct xe_lrc *lrc);
83 struct iosys_map xe_lrc_parallel_map(struct xe_lrc *lrc);
84
85 size_t xe_lrc_skip_size(struct xe_device *xe);
86
87 void xe_lrc_dump_default(struct drm_printer *p,
88 struct xe_gt *gt,
89 enum xe_engine_class);
90
91 void xe_lrc_emit_hwe_state_instructions(struct xe_exec_queue *q, struct xe_bb *bb);
92
93 struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc);
94 void xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot);
95 void xe_lrc_snapshot_print(struct xe_lrc_snapshot *snapshot, struct drm_printer *p);
96 void xe_lrc_snapshot_free(struct xe_lrc_snapshot *snapshot);
97
98 u32 xe_lrc_ctx_timestamp_ggtt_addr(struct xe_lrc *lrc);
99 u32 xe_lrc_ctx_timestamp(struct xe_lrc *lrc);
100 u32 xe_lrc_ctx_job_timestamp_ggtt_addr(struct xe_lrc *lrc);
101 u32 xe_lrc_ctx_job_timestamp(struct xe_lrc *lrc);
102
103 /**
104 * xe_lrc_update_timestamp - readout LRC timestamp and update cached value
105 * @lrc: logical ring context for this exec queue
106 * @old_ts: pointer where to save the previous timestamp
107 *
108 * Read the current timestamp for this LRC and update the cached value. The
109 * previous cached value is also returned in @old_ts so the caller can calculate
110 * the delta between 2 updates. Note that this is not intended to be called from
111 * any place, but just by the paths updating the drm client utilization.
112 *
113 * Returns the current LRC timestamp
114 */
115 u32 xe_lrc_update_timestamp(struct xe_lrc *lrc, u32 *old_ts);
116
117 #endif
118