1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright �� 2022 Intel Corporation
4 */
5
6#ifndef _XE_RTP_TYPES_
7#define _XE_RTP_TYPES_
8
9#include <linux/types.h>
10
11#include "regs/xe_reg_defs.h"
12
13struct xe_hw_engine;
14struct xe_gt;
15
16/**
17 * struct xe_rtp_action - action to take for any matching rule
18 *
19 * This struct records what action should be taken in a register that has a
20 * matching rule. Example of actions: set/clear bits.
21 */
22struct xe_rtp_action {
23	/** @reg: Register */
24	struct xe_reg		reg;
25	/**
26	 * @clr_bits: bits to clear when updating register. It's always a
27	 * superset of bits being modified
28	 */
29	u32			clr_bits;
30	/** @set_bits: bits to set when updating register */
31	u32			set_bits;
32#define XE_RTP_NOCHECK		.read_mask = 0
33	/** @read_mask: mask for bits to consider when reading value back */
34	u32			read_mask;
35#define XE_RTP_ACTION_FLAG_ENGINE_BASE		BIT(0)
36	/** @flags: flags to apply on rule evaluation or action */
37	u8			flags;
38};
39
40enum {
41	XE_RTP_MATCH_PLATFORM,
42	XE_RTP_MATCH_SUBPLATFORM,
43	XE_RTP_MATCH_GRAPHICS_VERSION,
44	XE_RTP_MATCH_GRAPHICS_VERSION_RANGE,
45	XE_RTP_MATCH_GRAPHICS_STEP,
46	XE_RTP_MATCH_MEDIA_VERSION,
47	XE_RTP_MATCH_MEDIA_VERSION_RANGE,
48	XE_RTP_MATCH_MEDIA_STEP,
49	XE_RTP_MATCH_INTEGRATED,
50	XE_RTP_MATCH_DISCRETE,
51	XE_RTP_MATCH_ENGINE_CLASS,
52	XE_RTP_MATCH_NOT_ENGINE_CLASS,
53	XE_RTP_MATCH_FUNC,
54};
55
56/** struct xe_rtp_rule - match rule for processing entry */
57struct xe_rtp_rule {
58	u8 match_type;
59
60	/* match filters */
61	union {
62		/* MATCH_PLATFORM / MATCH_SUBPLATFORM */
63		struct {
64			u8 platform;
65			u8 subplatform;
66		};
67		/*
68		 * MATCH_GRAPHICS_VERSION / XE_RTP_MATCH_GRAPHICS_VERSION_RANGE /
69		 * MATCH_MEDIA_VERSION  / XE_RTP_MATCH_MEDIA_VERSION_RANGE
70		 */
71		struct {
72			u32 ver_start;
73#define XE_RTP_END_VERSION_UNDEFINED	U32_MAX
74			u32 ver_end;
75		};
76		/* MATCH_STEP */
77		struct {
78			u8 step_start;
79			u8 step_end;
80		};
81		/* MATCH_ENGINE_CLASS / MATCH_NOT_ENGINE_CLASS */
82		struct {
83			u8 engine_class;
84		};
85		/* MATCH_FUNC */
86		bool (*match_func)(const struct xe_gt *gt,
87				   const struct xe_hw_engine *hwe);
88	};
89};
90
91/** struct xe_rtp_entry_sr - Entry in an rtp table */
92struct xe_rtp_entry_sr {
93	const char *name;
94	const struct xe_rtp_action *actions;
95	const struct xe_rtp_rule *rules;
96	u8 n_rules;
97	u8 n_actions;
98#define XE_RTP_ENTRY_FLAG_FOREACH_ENGINE	BIT(0)
99	u8 flags;
100};
101
102/** struct xe_rtp_entry - Entry in an rtp table, with no action associated */
103struct xe_rtp_entry {
104	const char *name;
105	const struct xe_rtp_rule *rules;
106	u8 n_rules;
107};
108
109enum xe_rtp_process_type {
110	XE_RTP_PROCESS_TYPE_GT,
111	XE_RTP_PROCESS_TYPE_ENGINE,
112};
113
114struct xe_rtp_process_ctx {
115	union {
116		struct xe_gt *gt;
117		struct xe_hw_engine *hwe;
118	};
119	enum xe_rtp_process_type type;
120	unsigned long *active_entries;
121	size_t n_entries;
122};
123
124#endif
125