1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2014 Intel Corporation
6 #ifndef __INTEL_LRC_H__
7 #define __INTEL_LRC_H__
9 #include <linux/types.h>
11 #include "intel_context.h"
12 #include "intel_lrc_reg.h"
14 struct drm_i915_gem_object;
15 struct intel_engine_cs;
18 /* At the start of the context image is its per-process HWS page */
19 #define LRC_PPHWSP_PN (0)
20 #define LRC_PPHWSP_SZ (1)
21 /* After the PPHWSP we have the logical state for the context */
22 #define LRC_STATE_PN (LRC_PPHWSP_PN + LRC_PPHWSP_SZ)
23 #define LRC_STATE_OFFSET (LRC_STATE_PN * PAGE_SIZE)
25 /* Space within PPHWSP reserved to be used as scratch */
26 #define LRC_PPHWSP_SCRATCH 0x34
27 #define LRC_PPHWSP_SCRATCH_ADDR (LRC_PPHWSP_SCRATCH * sizeof(u32))
29 void lrc_init_wa_ctx(struct intel_engine_cs *engine);
30 void lrc_fini_wa_ctx(struct intel_engine_cs *engine);
32 int lrc_alloc(struct intel_context *ce,
33 struct intel_engine_cs *engine);
34 void lrc_reset(struct intel_context *ce);
35 void lrc_fini(struct intel_context *ce);
36 void lrc_destroy(struct kref *kref);
39 lrc_pre_pin(struct intel_context *ce,
40 struct intel_engine_cs *engine,
41 struct i915_gem_ww_ctx *ww,
44 lrc_pin(struct intel_context *ce,
45 struct intel_engine_cs *engine,
47 void lrc_unpin(struct intel_context *ce);
48 void lrc_post_unpin(struct intel_context *ce);
50 void lrc_init_state(struct intel_context *ce,
51 struct intel_engine_cs *engine,
54 void lrc_init_regs(const struct intel_context *ce,
55 const struct intel_engine_cs *engine,
57 void lrc_reset_regs(const struct intel_context *ce,
58 const struct intel_engine_cs *engine);
60 u32 lrc_update_regs(const struct intel_context *ce,
61 const struct intel_engine_cs *engine,
63 void lrc_update_offsets(struct intel_context *ce,
64 struct intel_engine_cs *engine);
66 void lrc_check_regs(const struct intel_context *ce,
67 const struct intel_engine_cs *engine,
70 void lrc_update_runtime(struct intel_context *ce);
71 static inline u32 lrc_get_runtime(const struct intel_context *ce)
74 * We can use either ppHWSP[16] which is recorded before the context
75 * switch (and so excludes the cost of context switches) or use the
76 * value from the context image itself, which is saved/restored earlier
77 * and so includes the cost of the save.
79 return READ_ONCE(ce->lrc_reg_state[CTX_TIMESTAMP]);
82 #endif /* __INTEL_LRC_H__ */