1a0d3fdb6SChris Wilson /* SPDX-License-Identifier: MIT */
2a0d3fdb6SChris Wilson /*
3a0d3fdb6SChris Wilson * Copyright © 2014 Intel Corporation
4a0d3fdb6SChris Wilson */
5a0d3fdb6SChris Wilson
6a0d3fdb6SChris Wilson #ifndef __INTEL_LRC_H__
7a0d3fdb6SChris Wilson #define __INTEL_LRC_H__
8a0d3fdb6SChris Wilson
9adfadb56SMatt Roper #include "i915_priolist_types.h"
10adfadb56SMatt Roper
11adfadb56SMatt Roper #include <linux/bitfield.h>
12a0d3fdb6SChris Wilson #include <linux/types.h>
13a0d3fdb6SChris Wilson
14bb6287cbSTvrtko Ursulin #include "intel_context.h"
15bb6287cbSTvrtko Ursulin
16a0d3fdb6SChris Wilson struct drm_i915_gem_object;
172bb116c7SJani Nikula struct i915_gem_ww_ctx;
18a0d3fdb6SChris Wilson struct intel_engine_cs;
19a0d3fdb6SChris Wilson struct intel_ring;
202bb116c7SJani Nikula struct kref;
21a0d3fdb6SChris Wilson
22a0d3fdb6SChris Wilson /* At the start of the context image is its per-process HWS page */
23a0d3fdb6SChris Wilson #define LRC_PPHWSP_PN (0)
24a0d3fdb6SChris Wilson #define LRC_PPHWSP_SZ (1)
25a0d3fdb6SChris Wilson /* After the PPHWSP we have the logical state for the context */
26a0d3fdb6SChris Wilson #define LRC_STATE_PN (LRC_PPHWSP_PN + LRC_PPHWSP_SZ)
27a0d3fdb6SChris Wilson #define LRC_STATE_OFFSET (LRC_STATE_PN * PAGE_SIZE)
28a0d3fdb6SChris Wilson
29a0d3fdb6SChris Wilson /* Space within PPHWSP reserved to be used as scratch */
30a0d3fdb6SChris Wilson #define LRC_PPHWSP_SCRATCH 0x34
31a0d3fdb6SChris Wilson #define LRC_PPHWSP_SCRATCH_ADDR (LRC_PPHWSP_SCRATCH * sizeof(u32))
32a0d3fdb6SChris Wilson
339a437ccbSChris Wilson void lrc_init_wa_ctx(struct intel_engine_cs *engine);
34a0d3fdb6SChris Wilson void lrc_fini_wa_ctx(struct intel_engine_cs *engine);
35a0d3fdb6SChris Wilson
36a0d3fdb6SChris Wilson int lrc_alloc(struct intel_context *ce,
37a0d3fdb6SChris Wilson struct intel_engine_cs *engine);
38a0d3fdb6SChris Wilson void lrc_reset(struct intel_context *ce);
39a0d3fdb6SChris Wilson void lrc_fini(struct intel_context *ce);
40a0d3fdb6SChris Wilson void lrc_destroy(struct kref *kref);
41a0d3fdb6SChris Wilson
42a0d3fdb6SChris Wilson int
43a0d3fdb6SChris Wilson lrc_pre_pin(struct intel_context *ce,
44a0d3fdb6SChris Wilson struct intel_engine_cs *engine,
45a0d3fdb6SChris Wilson struct i915_gem_ww_ctx *ww,
46a0d3fdb6SChris Wilson void **vaddr);
47a0d3fdb6SChris Wilson int
48a0d3fdb6SChris Wilson lrc_pin(struct intel_context *ce,
49a0d3fdb6SChris Wilson struct intel_engine_cs *engine,
50a0d3fdb6SChris Wilson void *vaddr);
51a0d3fdb6SChris Wilson void lrc_unpin(struct intel_context *ce);
52a0d3fdb6SChris Wilson void lrc_post_unpin(struct intel_context *ce);
53a0d3fdb6SChris Wilson
54a0d3fdb6SChris Wilson void lrc_init_state(struct intel_context *ce,
55a0d3fdb6SChris Wilson struct intel_engine_cs *engine,
56a0d3fdb6SChris Wilson void *state);
57a0d3fdb6SChris Wilson
58a0d3fdb6SChris Wilson void lrc_init_regs(const struct intel_context *ce,
59a0d3fdb6SChris Wilson const struct intel_engine_cs *engine,
60a0d3fdb6SChris Wilson bool clear);
61a0d3fdb6SChris Wilson void lrc_reset_regs(const struct intel_context *ce,
62a0d3fdb6SChris Wilson const struct intel_engine_cs *engine);
63a0d3fdb6SChris Wilson
64a0d3fdb6SChris Wilson u32 lrc_update_regs(const struct intel_context *ce,
65a0d3fdb6SChris Wilson const struct intel_engine_cs *engine,
66a0d3fdb6SChris Wilson u32 head);
67a0d3fdb6SChris Wilson void lrc_update_offsets(struct intel_context *ce,
68a0d3fdb6SChris Wilson struct intel_engine_cs *engine);
69a0d3fdb6SChris Wilson
70a0d3fdb6SChris Wilson void lrc_check_regs(const struct intel_context *ce,
71a0d3fdb6SChris Wilson const struct intel_engine_cs *engine,
72a0d3fdb6SChris Wilson const char *when);
73a0d3fdb6SChris Wilson
74a0d3fdb6SChris Wilson void lrc_update_runtime(struct intel_context *ce);
75a0d3fdb6SChris Wilson
76f4c1fdb9SMatt Roper enum {
77f4c1fdb9SMatt Roper INTEL_ADVANCED_CONTEXT = 0,
78f4c1fdb9SMatt Roper INTEL_LEGACY_32B_CONTEXT,
79f4c1fdb9SMatt Roper INTEL_ADVANCED_AD_CONTEXT,
80f4c1fdb9SMatt Roper INTEL_LEGACY_64B_CONTEXT
81f4c1fdb9SMatt Roper };
82f4c1fdb9SMatt Roper
83f4c1fdb9SMatt Roper enum {
84f4c1fdb9SMatt Roper FAULT_AND_HANG = 0,
85f4c1fdb9SMatt Roper FAULT_AND_HALT, /* Debug only */
86f4c1fdb9SMatt Roper FAULT_AND_STREAM,
87f4c1fdb9SMatt Roper FAULT_AND_CONTINUE /* Unsupported */
88f4c1fdb9SMatt Roper };
89f4c1fdb9SMatt Roper
90f4c1fdb9SMatt Roper #define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)
91f4c1fdb9SMatt Roper #define GEN8_CTX_VALID (1 << 0)
92f4c1fdb9SMatt Roper #define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)
93f4c1fdb9SMatt Roper #define GEN8_CTX_FORCE_RESTORE (1 << 2)
94f4c1fdb9SMatt Roper #define GEN8_CTX_L3LLC_COHERENT (1 << 5)
95f4c1fdb9SMatt Roper #define GEN8_CTX_PRIVILEGE (1 << 8)
96f4c1fdb9SMatt Roper #define GEN8_CTX_ADDRESSING_MODE_SHIFT 3
97adfadb56SMatt Roper #define GEN12_CTX_PRIORITY_MASK GENMASK(10, 9)
98adfadb56SMatt Roper #define GEN12_CTX_PRIORITY_HIGH FIELD_PREP(GEN12_CTX_PRIORITY_MASK, 2)
99adfadb56SMatt Roper #define GEN12_CTX_PRIORITY_NORMAL FIELD_PREP(GEN12_CTX_PRIORITY_MASK, 1)
100adfadb56SMatt Roper #define GEN12_CTX_PRIORITY_LOW FIELD_PREP(GEN12_CTX_PRIORITY_MASK, 0)
101f4c1fdb9SMatt Roper #define GEN8_CTX_ID_SHIFT 32
102f4c1fdb9SMatt Roper #define GEN8_CTX_ID_WIDTH 21
103f4c1fdb9SMatt Roper #define GEN11_SW_CTX_ID_SHIFT 37
104f4c1fdb9SMatt Roper #define GEN11_SW_CTX_ID_WIDTH 11
105f4c1fdb9SMatt Roper #define GEN11_ENGINE_CLASS_SHIFT 61
106f4c1fdb9SMatt Roper #define GEN11_ENGINE_CLASS_WIDTH 3
107f4c1fdb9SMatt Roper #define GEN11_ENGINE_INSTANCE_SHIFT 48
108f4c1fdb9SMatt Roper #define GEN11_ENGINE_INSTANCE_WIDTH 6
109f4c1fdb9SMatt Roper #define XEHP_SW_CTX_ID_SHIFT 39
110f4c1fdb9SMatt Roper #define XEHP_SW_CTX_ID_WIDTH 16
111f4c1fdb9SMatt Roper #define XEHP_SW_COUNTER_SHIFT 58
112f4c1fdb9SMatt Roper #define XEHP_SW_COUNTER_WIDTH 6
113*682aa437SUmesh Nerlige Ramappa #define GEN12_GUC_SW_CTX_ID_SHIFT 39
114*682aa437SUmesh Nerlige Ramappa #define GEN12_GUC_SW_CTX_ID_WIDTH 16
115f4c1fdb9SMatt Roper
lrc_runtime_start(struct intel_context * ce)116bb6287cbSTvrtko Ursulin static inline void lrc_runtime_start(struct intel_context *ce)
117bb6287cbSTvrtko Ursulin {
118bb6287cbSTvrtko Ursulin struct intel_context_stats *stats = &ce->stats;
119bb6287cbSTvrtko Ursulin
120bb6287cbSTvrtko Ursulin if (intel_context_is_barrier(ce))
121bb6287cbSTvrtko Ursulin return;
122bb6287cbSTvrtko Ursulin
123bb6287cbSTvrtko Ursulin if (stats->active)
124bb6287cbSTvrtko Ursulin return;
125bb6287cbSTvrtko Ursulin
126bb6287cbSTvrtko Ursulin WRITE_ONCE(stats->active, intel_context_clock());
127bb6287cbSTvrtko Ursulin }
128bb6287cbSTvrtko Ursulin
lrc_runtime_stop(struct intel_context * ce)129bb6287cbSTvrtko Ursulin static inline void lrc_runtime_stop(struct intel_context *ce)
130bb6287cbSTvrtko Ursulin {
131bb6287cbSTvrtko Ursulin struct intel_context_stats *stats = &ce->stats;
132bb6287cbSTvrtko Ursulin
133bb6287cbSTvrtko Ursulin if (!stats->active)
134bb6287cbSTvrtko Ursulin return;
135bb6287cbSTvrtko Ursulin
136bb6287cbSTvrtko Ursulin lrc_update_runtime(ce);
137bb6287cbSTvrtko Ursulin WRITE_ONCE(stats->active, 0);
138bb6287cbSTvrtko Ursulin }
139bb6287cbSTvrtko Ursulin
140166c44e6SChris Wilson #define DG2_PREDICATE_RESULT_WA (PAGE_SIZE - sizeof(u64))
141166c44e6SChris Wilson #define DG2_PREDICATE_RESULT_BB (2048)
142166c44e6SChris Wilson
143166c44e6SChris Wilson u32 lrc_indirect_bb(const struct intel_context *ce);
144166c44e6SChris Wilson
145a0d3fdb6SChris Wilson #endif /* __INTEL_LRC_H__ */
146