xref: /openbmc/linux/drivers/gpu/drm/i915/gt/intel_lrc.h (revision 31e67366)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2014 Intel Corporation
4  */
5 
6 #ifndef __INTEL_LRC_H__
7 #define __INTEL_LRC_H__
8 
9 #include <linux/types.h>
10 
11 #include "intel_context.h"
12 #include "intel_lrc_reg.h"
13 
14 struct drm_i915_gem_object;
15 struct intel_engine_cs;
16 struct intel_ring;
17 
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)
24 
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))
28 
29 void lrc_init_wa_ctx(struct intel_engine_cs *engine);
30 void lrc_fini_wa_ctx(struct intel_engine_cs *engine);
31 
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);
37 
38 int
39 lrc_pre_pin(struct intel_context *ce,
40 	    struct intel_engine_cs *engine,
41 	    struct i915_gem_ww_ctx *ww,
42 	    void **vaddr);
43 int
44 lrc_pin(struct intel_context *ce,
45 	struct intel_engine_cs *engine,
46 	void *vaddr);
47 void lrc_unpin(struct intel_context *ce);
48 void lrc_post_unpin(struct intel_context *ce);
49 
50 void lrc_init_state(struct intel_context *ce,
51 		    struct intel_engine_cs *engine,
52 		    void *state);
53 
54 void lrc_init_regs(const struct intel_context *ce,
55 		   const struct intel_engine_cs *engine,
56 		   bool clear);
57 void lrc_reset_regs(const struct intel_context *ce,
58 		    const struct intel_engine_cs *engine);
59 
60 u32 lrc_update_regs(const struct intel_context *ce,
61 		    const struct intel_engine_cs *engine,
62 		    u32 head);
63 void lrc_update_offsets(struct intel_context *ce,
64 			struct intel_engine_cs *engine);
65 
66 void lrc_check_regs(const struct intel_context *ce,
67 		    const struct intel_engine_cs *engine,
68 		    const char *when);
69 
70 void lrc_update_runtime(struct intel_context *ce);
71 static inline u32 lrc_get_runtime(const struct intel_context *ce)
72 {
73 	/*
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.
78 	 */
79 	return READ_ONCE(ce->lrc_reg_state[CTX_TIMESTAMP]);
80 }
81 
82 #endif /* __INTEL_LRC_H__ */
83