xref: /linux/drivers/gpu/drm/i915/gt/intel_gt_mcr.c (revision db5d28c0bfe566908719bec8e25443aabecbb802)
1e7858254SMatt Roper // SPDX-License-Identifier: MIT
2e7858254SMatt Roper /*
3e7858254SMatt Roper  * Copyright © 2022 Intel Corporation
4e7858254SMatt Roper  */
5e7858254SMatt Roper 
682b1e8f7SJani Nikula #include "i915_drv.h"
75a213086SMatt Roper #include "intel_gt.h"
8e7858254SMatt Roper #include "intel_gt_mcr.h"
967804e48SJohn Harrison #include "intel_gt_print.h"
10e7858254SMatt Roper #include "intel_gt_regs.h"
11e7858254SMatt Roper 
12e7858254SMatt Roper /**
13e7858254SMatt Roper  * DOC: GT Multicast/Replicated (MCR) Register Support
14e7858254SMatt Roper  *
15e7858254SMatt Roper  * Some GT registers are designed as "multicast" or "replicated" registers:
16e7858254SMatt Roper  * multiple instances of the same register share a single MMIO offset.  MCR
17e7858254SMatt Roper  * registers are generally used when the hardware needs to potentially track
18e7858254SMatt Roper  * independent values of a register per hardware unit (e.g., per-subslice,
19e7858254SMatt Roper  * per-L3bank, etc.).  The specific types of replication that exist vary
20e7858254SMatt Roper  * per-platform.
21e7858254SMatt Roper  *
22e7858254SMatt Roper  * MMIO accesses to MCR registers are controlled according to the settings
23e7858254SMatt Roper  * programmed in the platform's MCR_SELECTOR register(s).  MMIO writes to MCR
24e7858254SMatt Roper  * registers can be done in either a (i.e., a single write updates all
25e7858254SMatt Roper  * instances of the register to the same value) or unicast (a write updates only
26e7858254SMatt Roper  * one specific instance).  Reads of MCR registers always operate in a unicast
27e7858254SMatt Roper  * manner regardless of how the multicast/unicast bit is set in MCR_SELECTOR.
28e7858254SMatt Roper  * Selection of a specific MCR instance for unicast operations is referred to
29e7858254SMatt Roper  * as "steering."
30e7858254SMatt Roper  *
31e7858254SMatt Roper  * If MCR register operations are steered toward a hardware unit that is
32e7858254SMatt Roper  * fused off or currently powered down due to power gating, the MMIO operation
33e7858254SMatt Roper  * is "terminated" by the hardware.  Terminated read operations will return a
34e7858254SMatt Roper  * value of zero and terminated unicast write operations will be silently
35e7858254SMatt Roper  * ignored.
36e7858254SMatt Roper  */
37e7858254SMatt Roper 
387416cbbcSAndi Shyti #define HAS_MSLICE_STEERING(i915)	(INTEL_INFO(i915)->has_mslice_steering)
39e7858254SMatt Roper 
40e7858254SMatt Roper static const char * const intel_steering_types[] = {
41e7858254SMatt Roper 	"L3BANK",
42e7858254SMatt Roper 	"MSLICE",
43e7858254SMatt Roper 	"LNCF",
4407a70f38SMatt Roper 	"GAM",
45f32898c9SMatt Roper 	"DSS",
46a7ec65fcSMatt Roper 	"OADDRM",
47e7858254SMatt Roper 	"INSTANCE 0",
48e7858254SMatt Roper };
49e7858254SMatt Roper 
50e7858254SMatt Roper static const struct intel_mmio_range icl_l3bank_steering_table[] = {
51e7858254SMatt Roper 	{ 0x00B100, 0x00B3FF },
52e7858254SMatt Roper 	{},
53e7858254SMatt Roper };
54e7858254SMatt Roper 
5507a70f38SMatt Roper /*
5607a70f38SMatt Roper  * Although the bspec lists more "MSLICE" ranges than shown here, some of those
5707a70f38SMatt Roper  * are of a "GAM" subclass that has special rules.  Thus we use a separate
5807a70f38SMatt Roper  * GAM table farther down for those.
5907a70f38SMatt Roper  */
60cb4046d2SLucas De Marchi static const struct intel_mmio_range dg2_mslice_steering_table[] = {
61e7858254SMatt Roper 	{ 0x00DD00, 0x00DDFF },
62e7858254SMatt Roper 	{ 0x00E900, 0x00FFFF }, /* 0xEA00 - OxEFFF is unused */
63e7858254SMatt Roper 	{},
64e7858254SMatt Roper };
65e7858254SMatt Roper 
66e7858254SMatt Roper static const struct intel_mmio_range dg2_lncf_steering_table[] = {
67e7858254SMatt Roper 	{ 0x00B000, 0x00B0FF },
68e7858254SMatt Roper 	{ 0x00D880, 0x00D8FF },
69e7858254SMatt Roper 	{},
70e7858254SMatt Roper };
71e7858254SMatt Roper 
72f32898c9SMatt Roper static const struct intel_mmio_range xelpg_instance0_steering_table[] = {
73f32898c9SMatt Roper 	{ 0x000B00, 0x000BFF },         /* SQIDI */
74f32898c9SMatt Roper 	{ 0x001000, 0x001FFF },         /* SQIDI */
75f32898c9SMatt Roper 	{ 0x004000, 0x0048FF },         /* GAM */
76f32898c9SMatt Roper 	{ 0x008700, 0x0087FF },         /* SQIDI */
77f32898c9SMatt Roper 	{ 0x00B000, 0x00B0FF },         /* NODE */
78f32898c9SMatt Roper 	{ 0x00C800, 0x00CFFF },         /* GAM */
79f32898c9SMatt Roper 	{ 0x00D880, 0x00D8FF },         /* NODE */
80f32898c9SMatt Roper 	{ 0x00DD00, 0x00DDFF },         /* OAAL2 */
81f32898c9SMatt Roper 	{},
82f32898c9SMatt Roper };
83f32898c9SMatt Roper 
84f32898c9SMatt Roper static const struct intel_mmio_range xelpg_l3bank_steering_table[] = {
85f32898c9SMatt Roper 	{ 0x00B100, 0x00B3FF },
86f32898c9SMatt Roper 	{},
87f32898c9SMatt Roper };
88f32898c9SMatt Roper 
89f32898c9SMatt Roper /* DSS steering is used for SLICE ranges as well */
90f32898c9SMatt Roper static const struct intel_mmio_range xelpg_dss_steering_table[] = {
91f32898c9SMatt Roper 	{ 0x005200, 0x0052FF },		/* SLICE */
92f32898c9SMatt Roper 	{ 0x005500, 0x007FFF },		/* SLICE */
93f32898c9SMatt Roper 	{ 0x008140, 0x00815F },		/* SLICE (0x8140-0x814F), DSS (0x8150-0x815F) */
94f32898c9SMatt Roper 	{ 0x0094D0, 0x00955F },		/* SLICE (0x94D0-0x951F), DSS (0x9520-0x955F) */
95f32898c9SMatt Roper 	{ 0x009680, 0x0096FF },		/* DSS */
96f32898c9SMatt Roper 	{ 0x00D800, 0x00D87F },		/* SLICE */
97f32898c9SMatt Roper 	{ 0x00DC00, 0x00DCFF },		/* SLICE */
98f32898c9SMatt Roper 	{ 0x00DE80, 0x00E8FF },		/* DSS (0xE000-0xE0FF reserved) */
99876e9047SMatt Roper 	{},
100f32898c9SMatt Roper };
101f32898c9SMatt Roper 
102a7ec65fcSMatt Roper static const struct intel_mmio_range xelpmp_oaddrm_steering_table[] = {
103a7ec65fcSMatt Roper 	{ 0x393200, 0x39323F },
104a7ec65fcSMatt Roper 	{ 0x393400, 0x3934FF },
105876e9047SMatt Roper 	{},
106a7ec65fcSMatt Roper };
107a7ec65fcSMatt Roper 
intel_gt_mcr_init(struct intel_gt * gt)108e7858254SMatt Roper void intel_gt_mcr_init(struct intel_gt *gt)
109e7858254SMatt Roper {
110e7858254SMatt Roper 	struct drm_i915_private *i915 = gt->i915;
111f32898c9SMatt Roper 	unsigned long fuse;
112f32898c9SMatt Roper 	int i;
113e7858254SMatt Roper 
1144186e218SMatt Roper 	spin_lock_init(&gt->mcr_lock);
1154186e218SMatt Roper 
116e7858254SMatt Roper 	/*
117e7858254SMatt Roper 	 * An mslice is unavailable only if both the meml3 for the slice is
118e7858254SMatt Roper 	 * disabled *and* all of the DSS in the slice (quadrant) are disabled.
119e7858254SMatt Roper 	 */
120e7858254SMatt Roper 	if (HAS_MSLICE_STEERING(i915)) {
121e7858254SMatt Roper 		gt->info.mslice_mask =
122e7858254SMatt Roper 			intel_slicemask_from_xehp_dssmask(gt->info.sseu.subslice_mask,
123e7858254SMatt Roper 							  GEN_DSS_PER_MSLICE);
124e7858254SMatt Roper 		gt->info.mslice_mask |=
125e7858254SMatt Roper 			(intel_uncore_read(gt->uncore, GEN10_MIRROR_FUSE3) &
126e7858254SMatt Roper 			 GEN12_MEML3_EN_MASK);
127e7858254SMatt Roper 
128e7858254SMatt Roper 		if (!gt->info.mslice_mask) /* should be impossible! */
12967804e48SJohn Harrison 			gt_warn(gt, "mslice mask all zero!\n");
130e7858254SMatt Roper 	}
131e7858254SMatt Roper 
132a7ec65fcSMatt Roper 	if (MEDIA_VER(i915) >= 13 && gt->type == GT_MEDIA) {
133a7ec65fcSMatt Roper 		gt->steering_table[OADDRM] = xelpmp_oaddrm_steering_table;
134a7ec65fcSMatt Roper 	} else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70)) {
13541bb543fSMatt Roper 		/* Wa_14016747170 */
1365a213086SMatt Roper 		if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) ||
1375a213086SMatt Roper 		    IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0))
13841bb543fSMatt Roper 			fuse = REG_FIELD_GET(MTL_GT_L3_EXC_MASK,
13941bb543fSMatt Roper 					     intel_uncore_read(gt->uncore,
14041bb543fSMatt Roper 							       MTL_GT_ACTIVITY_FACTOR));
14141bb543fSMatt Roper 		else
142f32898c9SMatt Roper 			fuse = REG_FIELD_GET(GT_L3_EXC_MASK,
143f32898c9SMatt Roper 					     intel_uncore_read(gt->uncore, XEHP_FUSE4));
144f32898c9SMatt Roper 
145f32898c9SMatt Roper 		/*
146f32898c9SMatt Roper 		 * Despite the register field being named "exclude mask" the
147f32898c9SMatt Roper 		 * bits actually represent enabled banks (two banks per bit).
148f32898c9SMatt Roper 		 */
149f32898c9SMatt Roper 		for_each_set_bit(i, &fuse, 3)
150f32898c9SMatt Roper 			gt->info.l3bank_mask |= 0x3 << 2 * i;
151f32898c9SMatt Roper 
152f32898c9SMatt Roper 		gt->steering_table[INSTANCE0] = xelpg_instance0_steering_table;
153f32898c9SMatt Roper 		gt->steering_table[L3BANK] = xelpg_l3bank_steering_table;
154f32898c9SMatt Roper 		gt->steering_table[DSS] = xelpg_dss_steering_table;
155e7858254SMatt Roper 	} else if (IS_DG2(i915)) {
156cb4046d2SLucas De Marchi 		gt->steering_table[MSLICE] = dg2_mslice_steering_table;
157e7858254SMatt Roper 		gt->steering_table[LNCF] = dg2_lncf_steering_table;
15807a70f38SMatt Roper 		/*
15907a70f38SMatt Roper 		 * No need to hook up the GAM table since it has a dedicated
16007a70f38SMatt Roper 		 * steering control register on DG2 and can use implicit
16107a70f38SMatt Roper 		 * steering.
16207a70f38SMatt Roper 		 */
163e7858254SMatt Roper 	} else if (GRAPHICS_VER(i915) >= 11 &&
16448ba4a6dSLucas De Marchi 		   GRAPHICS_VER_FULL(i915) < IP_VER(12, 55)) {
165e7858254SMatt Roper 		gt->steering_table[L3BANK] = icl_l3bank_steering_table;
166e7858254SMatt Roper 		gt->info.l3bank_mask =
167e7858254SMatt Roper 			~intel_uncore_read(gt->uncore, GEN10_MIRROR_FUSE3) &
168e7858254SMatt Roper 			GEN10_L3BANK_MASK;
169e7858254SMatt Roper 		if (!gt->info.l3bank_mask) /* should be impossible! */
17067804e48SJohn Harrison 			gt_warn(gt, "L3 bank mask is all zero!\n");
171e7858254SMatt Roper 	} else if (GRAPHICS_VER(i915) >= 11) {
172e7858254SMatt Roper 		/*
173e7858254SMatt Roper 		 * We expect all modern platforms to have at least some
174e7858254SMatt Roper 		 * type of steering that needs to be initialized.
175e7858254SMatt Roper 		 */
176e7858254SMatt Roper 		MISSING_CASE(INTEL_INFO(i915)->platform);
177e7858254SMatt Roper 	}
178e7858254SMatt Roper }
179e7858254SMatt Roper 
1803fe6c7f5SMatt Roper /*
18158bc2453SMatt Roper  * Although the rest of the driver should use MCR-specific functions to
18258bc2453SMatt Roper  * read/write MCR registers, we still use the regular intel_uncore_* functions
18358bc2453SMatt Roper  * internally to implement those, so we need a way for the functions in this
18458bc2453SMatt Roper  * file to "cast" an i915_mcr_reg_t into an i915_reg_t.
18558bc2453SMatt Roper  */
mcr_reg_cast(const i915_mcr_reg_t mcr)18658bc2453SMatt Roper static i915_reg_t mcr_reg_cast(const i915_mcr_reg_t mcr)
18758bc2453SMatt Roper {
18858bc2453SMatt Roper 	i915_reg_t r = { .reg = mcr.reg };
18958bc2453SMatt Roper 
19058bc2453SMatt Roper 	return r;
19158bc2453SMatt Roper }
19258bc2453SMatt Roper 
19358bc2453SMatt Roper /*
1943fe6c7f5SMatt Roper  * rw_with_mcr_steering_fw - Access a register with specific MCR steering
1958d9f7d25SMatt Roper  * @gt: GT to read register from
196e7858254SMatt Roper  * @reg: register being accessed
197e7858254SMatt Roper  * @rw_flag: FW_REG_READ for read access or FW_REG_WRITE for write access
1983fe6c7f5SMatt Roper  * @group: group number (documented as "sliceid" on older platforms)
1993fe6c7f5SMatt Roper  * @instance: instance number (documented as "subsliceid" on older platforms)
200e7858254SMatt Roper  * @value: register value to be written (ignored for read)
201e7858254SMatt Roper  *
2024186e218SMatt Roper  * Context: The caller must hold the MCR lock
203e7858254SMatt Roper  * Return: 0 for write access. register value for read access.
204e7858254SMatt Roper  *
205e7858254SMatt Roper  * Caller needs to make sure the relevant forcewake wells are up.
206e7858254SMatt Roper  */
rw_with_mcr_steering_fw(struct intel_gt * gt,i915_mcr_reg_t reg,u8 rw_flag,int group,int instance,u32 value)2078d9f7d25SMatt Roper static u32 rw_with_mcr_steering_fw(struct intel_gt *gt,
20858bc2453SMatt Roper 				   i915_mcr_reg_t reg, u8 rw_flag,
2093fe6c7f5SMatt Roper 				   int group, int instance, u32 value)
210e7858254SMatt Roper {
2118d9f7d25SMatt Roper 	struct intel_uncore *uncore = gt->uncore;
212e7858254SMatt Roper 	u32 mcr_mask, mcr_ss, mcr, old_mcr, val = 0;
213e7858254SMatt Roper 
2144186e218SMatt Roper 	lockdep_assert_held(&gt->mcr_lock);
215e7858254SMatt Roper 
216f32898c9SMatt Roper 	if (GRAPHICS_VER_FULL(uncore->i915) >= IP_VER(12, 70)) {
217f32898c9SMatt Roper 		/*
218f32898c9SMatt Roper 		 * Always leave the hardware in multicast mode when doing reads
219f32898c9SMatt Roper 		 * (see comment about Wa_22013088509 below) and only change it
220f32898c9SMatt Roper 		 * to unicast mode when doing writes of a specific instance.
221f32898c9SMatt Roper 		 *
222f32898c9SMatt Roper 		 * No need to save old steering reg value.
223f32898c9SMatt Roper 		 */
224f32898c9SMatt Roper 		intel_uncore_write_fw(uncore, MTL_MCR_SELECTOR,
225f32898c9SMatt Roper 				      REG_FIELD_PREP(MTL_MCR_GROUPID, group) |
226f32898c9SMatt Roper 				      REG_FIELD_PREP(MTL_MCR_INSTANCEID, instance) |
227a47e8a46SMatt Roper 				      (rw_flag == FW_REG_READ ? GEN11_MCR_MULTICAST : 0));
228f32898c9SMatt Roper 	} else if (GRAPHICS_VER(uncore->i915) >= 11) {
229e7858254SMatt Roper 		mcr_mask = GEN11_MCR_SLICE_MASK | GEN11_MCR_SUBSLICE_MASK;
2303fe6c7f5SMatt Roper 		mcr_ss = GEN11_MCR_SLICE(group) | GEN11_MCR_SUBSLICE(instance);
231e7858254SMatt Roper 
232e7858254SMatt Roper 		/*
233e7858254SMatt Roper 		 * Wa_22013088509
234e7858254SMatt Roper 		 *
235e7858254SMatt Roper 		 * The setting of the multicast/unicast bit usually wouldn't
236e7858254SMatt Roper 		 * matter for read operations (which always return the value
237e7858254SMatt Roper 		 * from a single register instance regardless of how that bit
238e7858254SMatt Roper 		 * is set), but some platforms have a workaround requiring us
239e7858254SMatt Roper 		 * to remain in multicast mode for reads.  There's no real
240e7858254SMatt Roper 		 * downside to this, so we'll just go ahead and do so on all
241e7858254SMatt Roper 		 * platforms; we'll only clear the multicast bit from the mask
242e7858254SMatt Roper 		 * when exlicitly doing a write operation.
243e7858254SMatt Roper 		 */
244e7858254SMatt Roper 		if (rw_flag == FW_REG_WRITE)
245e7858254SMatt Roper 			mcr_mask |= GEN11_MCR_MULTICAST;
246e7858254SMatt Roper 
247f32898c9SMatt Roper 		mcr = intel_uncore_read_fw(uncore, GEN8_MCR_SELECTOR);
248f32898c9SMatt Roper 		old_mcr = mcr;
249e7858254SMatt Roper 
250e7858254SMatt Roper 		mcr &= ~mcr_mask;
251e7858254SMatt Roper 		mcr |= mcr_ss;
252e7858254SMatt Roper 		intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, mcr);
253f32898c9SMatt Roper 	} else {
254f32898c9SMatt Roper 		mcr_mask = GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK;
255f32898c9SMatt Roper 		mcr_ss = GEN8_MCR_SLICE(group) | GEN8_MCR_SUBSLICE(instance);
256f32898c9SMatt Roper 
257f32898c9SMatt Roper 		mcr = intel_uncore_read_fw(uncore, GEN8_MCR_SELECTOR);
258f32898c9SMatt Roper 		old_mcr = mcr;
259f32898c9SMatt Roper 
260f32898c9SMatt Roper 		mcr &= ~mcr_mask;
261f32898c9SMatt Roper 		mcr |= mcr_ss;
262f32898c9SMatt Roper 		intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, mcr);
263f32898c9SMatt Roper 	}
264e7858254SMatt Roper 
265e7858254SMatt Roper 	if (rw_flag == FW_REG_READ)
26658bc2453SMatt Roper 		val = intel_uncore_read_fw(uncore, mcr_reg_cast(reg));
267e7858254SMatt Roper 	else
26858bc2453SMatt Roper 		intel_uncore_write_fw(uncore, mcr_reg_cast(reg), value);
269e7858254SMatt Roper 
270f32898c9SMatt Roper 	/*
271f32898c9SMatt Roper 	 * For pre-MTL platforms, we need to restore the old value of the
272f32898c9SMatt Roper 	 * steering control register to ensure that implicit steering continues
273f32898c9SMatt Roper 	 * to behave as expected.  For MTL and beyond, we need only reinstate
274f32898c9SMatt Roper 	 * the 'multicast' bit (and only if we did a write that cleared it).
275f32898c9SMatt Roper 	 */
276f32898c9SMatt Roper 	if (GRAPHICS_VER_FULL(uncore->i915) >= IP_VER(12, 70) && rw_flag == FW_REG_WRITE)
277f32898c9SMatt Roper 		intel_uncore_write_fw(uncore, MTL_MCR_SELECTOR, GEN11_MCR_MULTICAST);
278f32898c9SMatt Roper 	else if (GRAPHICS_VER_FULL(uncore->i915) < IP_VER(12, 70))
279f32898c9SMatt Roper 		intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, old_mcr);
280e7858254SMatt Roper 
281e7858254SMatt Roper 	return val;
282e7858254SMatt Roper }
283e7858254SMatt Roper 
rw_with_mcr_steering(struct intel_gt * gt,i915_mcr_reg_t reg,u8 rw_flag,int group,int instance,u32 value)2848d9f7d25SMatt Roper static u32 rw_with_mcr_steering(struct intel_gt *gt,
28558bc2453SMatt Roper 				i915_mcr_reg_t reg, u8 rw_flag,
2863fe6c7f5SMatt Roper 				int group, int instance,
287e7858254SMatt Roper 				u32 value)
288e7858254SMatt Roper {
2898d9f7d25SMatt Roper 	struct intel_uncore *uncore = gt->uncore;
290e7858254SMatt Roper 	enum forcewake_domains fw_domains;
2914186e218SMatt Roper 	unsigned long flags;
292e7858254SMatt Roper 	u32 val;
293e7858254SMatt Roper 
29458bc2453SMatt Roper 	fw_domains = intel_uncore_forcewake_for_reg(uncore, mcr_reg_cast(reg),
295e7858254SMatt Roper 						    rw_flag);
296e7858254SMatt Roper 	fw_domains |= intel_uncore_forcewake_for_reg(uncore,
297e7858254SMatt Roper 						     GEN8_MCR_SELECTOR,
298e7858254SMatt Roper 						     FW_REG_READ | FW_REG_WRITE);
299e7858254SMatt Roper 
3004186e218SMatt Roper 	intel_gt_mcr_lock(gt, &flags);
3014186e218SMatt Roper 	spin_lock(&uncore->lock);
302e7858254SMatt Roper 	intel_uncore_forcewake_get__locked(uncore, fw_domains);
303e7858254SMatt Roper 
3048d9f7d25SMatt Roper 	val = rw_with_mcr_steering_fw(gt, reg, rw_flag, group, instance, value);
305e7858254SMatt Roper 
306e7858254SMatt Roper 	intel_uncore_forcewake_put__locked(uncore, fw_domains);
3074186e218SMatt Roper 	spin_unlock(&uncore->lock);
3084186e218SMatt Roper 	intel_gt_mcr_unlock(gt, flags);
309e7858254SMatt Roper 
310e7858254SMatt Roper 	return val;
311e7858254SMatt Roper }
312e7858254SMatt Roper 
3133fe6c7f5SMatt Roper /**
3144186e218SMatt Roper  * intel_gt_mcr_lock - Acquire MCR steering lock
3154186e218SMatt Roper  * @gt: GT structure
3164186e218SMatt Roper  * @flags: storage to save IRQ flags to
3174186e218SMatt Roper  *
3184186e218SMatt Roper  * Performs locking to protect the steering for the duration of an MCR
3193100240bSMatt Roper  * operation.  On MTL and beyond, a hardware lock will also be taken to
3203100240bSMatt Roper  * serialize access not only for the driver, but also for external hardware and
3213100240bSMatt Roper  * firmware agents.
3224186e218SMatt Roper  *
3234186e218SMatt Roper  * Context: Takes gt->mcr_lock.  uncore->lock should *not* be held when this
3244186e218SMatt Roper  *          function is called, although it may be acquired after this
3254186e218SMatt Roper  *          function call.
3264186e218SMatt Roper  */
intel_gt_mcr_lock(struct intel_gt * gt,unsigned long * flags)3274186e218SMatt Roper void intel_gt_mcr_lock(struct intel_gt *gt, unsigned long *flags)
328aae4f817SJani Nikula 	__acquires(&gt->mcr_lock)
3294186e218SMatt Roper {
3304186e218SMatt Roper 	unsigned long __flags;
3313100240bSMatt Roper 	int err = 0;
3324186e218SMatt Roper 
3334186e218SMatt Roper 	lockdep_assert_not_held(&gt->uncore->lock);
3344186e218SMatt Roper 
3353100240bSMatt Roper 	/*
3363100240bSMatt Roper 	 * Starting with MTL, we need to coordinate not only with other
3373100240bSMatt Roper 	 * driver threads, but also with hardware/firmware agents.  A dedicated
3383100240bSMatt Roper 	 * locking register is used.
3393100240bSMatt Roper 	 */
3408fa1c7cdSMatt Roper 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70)) {
3418fa1c7cdSMatt Roper 		/*
3428fa1c7cdSMatt Roper 		 * The steering control and semaphore registers are inside an
3438fa1c7cdSMatt Roper 		 * "always on" power domain with respect to RC6.  However there
3448fa1c7cdSMatt Roper 		 * are some issues if higher-level platform sleep states are
3458fa1c7cdSMatt Roper 		 * entering/exiting at the same time these registers are
3468fa1c7cdSMatt Roper 		 * accessed.  Grabbing GT forcewake and holding it over the
3478fa1c7cdSMatt Roper 		 * entire lock/steer/unlock cycle ensures that those sleep
3488fa1c7cdSMatt Roper 		 * states have been fully exited before we access these
3498fa1c7cdSMatt Roper 		 * registers.  This wakeref will be released in the unlock
3508fa1c7cdSMatt Roper 		 * routine.
3518fa1c7cdSMatt Roper 		 *
3523c7a5eb7SRadhakrishna Sripada 		 * Wa_22018931422
3538fa1c7cdSMatt Roper 		 */
3548fa1c7cdSMatt Roper 		intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_GT);
3558fa1c7cdSMatt Roper 
3563100240bSMatt Roper 		err = wait_for(intel_uncore_read_fw(gt->uncore,
3573100240bSMatt Roper 						    MTL_STEER_SEMAPHORE) == 0x1, 100);
3588fa1c7cdSMatt Roper 	}
3593100240bSMatt Roper 
3603100240bSMatt Roper 	/*
3613100240bSMatt Roper 	 * Even on platforms with a hardware lock, we'll continue to grab
3623100240bSMatt Roper 	 * a software spinlock too for lockdep purposes.  If the hardware lock
3633100240bSMatt Roper 	 * was already acquired, there should never be contention on the
3643100240bSMatt Roper 	 * software lock.
3653100240bSMatt Roper 	 */
3664186e218SMatt Roper 	spin_lock_irqsave(&gt->mcr_lock, __flags);
3674186e218SMatt Roper 
3684186e218SMatt Roper 	*flags = __flags;
3693100240bSMatt Roper 
3703100240bSMatt Roper 	/*
3713100240bSMatt Roper 	 * In theory we should never fail to acquire the HW semaphore; this
3723100240bSMatt Roper 	 * would indicate some hardware/firmware is misbehaving and not
3733100240bSMatt Roper 	 * releasing it properly.
3743100240bSMatt Roper 	 */
3753100240bSMatt Roper 	if (err == -ETIMEDOUT) {
37667804e48SJohn Harrison 		gt_err_ratelimited(gt, "hardware MCR steering semaphore timed out");
3773100240bSMatt Roper 		add_taint_for_CI(gt->i915, TAINT_WARN);  /* CI is now unreliable */
3783100240bSMatt Roper 	}
3794186e218SMatt Roper }
3804186e218SMatt Roper 
3814186e218SMatt Roper /**
3824186e218SMatt Roper  * intel_gt_mcr_unlock - Release MCR steering lock
3834186e218SMatt Roper  * @gt: GT structure
3844186e218SMatt Roper  * @flags: IRQ flags to restore
3854186e218SMatt Roper  *
3864186e218SMatt Roper  * Releases the lock acquired by intel_gt_mcr_lock().
3874186e218SMatt Roper  *
3884186e218SMatt Roper  * Context: Releases gt->mcr_lock
3894186e218SMatt Roper  */
intel_gt_mcr_unlock(struct intel_gt * gt,unsigned long flags)3904186e218SMatt Roper void intel_gt_mcr_unlock(struct intel_gt *gt, unsigned long flags)
391aae4f817SJani Nikula 	__releases(&gt->mcr_lock)
3924186e218SMatt Roper {
3934186e218SMatt Roper 	spin_unlock_irqrestore(&gt->mcr_lock, flags);
3943100240bSMatt Roper 
3958fa1c7cdSMatt Roper 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70)) {
3963100240bSMatt Roper 		intel_uncore_write_fw(gt->uncore, MTL_STEER_SEMAPHORE, 0x1);
3978fa1c7cdSMatt Roper 
3988fa1c7cdSMatt Roper 		intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_GT);
3998fa1c7cdSMatt Roper 	}
4004186e218SMatt Roper }
4014186e218SMatt Roper 
4024186e218SMatt Roper /**
40342a71bbaSNirmoy Das  * intel_gt_mcr_lock_sanitize - Sanitize MCR steering lock
40442a71bbaSNirmoy Das  * @gt: GT structure
40542a71bbaSNirmoy Das  *
40642a71bbaSNirmoy Das  * This will be used to sanitize the initial status of the hardware lock
40742a71bbaSNirmoy Das  * during driver load and resume since there won't be any concurrent access
40842a71bbaSNirmoy Das  * from other agents at those times, but it's possible that boot firmware
40942a71bbaSNirmoy Das  * may have left the lock in a bad state.
41042a71bbaSNirmoy Das  *
41142a71bbaSNirmoy Das  */
intel_gt_mcr_lock_sanitize(struct intel_gt * gt)41242a71bbaSNirmoy Das void intel_gt_mcr_lock_sanitize(struct intel_gt *gt)
41342a71bbaSNirmoy Das {
41442a71bbaSNirmoy Das 	/*
41542a71bbaSNirmoy Das 	 * This gets called at load/resume time, so we shouldn't be
41642a71bbaSNirmoy Das 	 * racing with other driver threads grabbing the mcr lock.
41742a71bbaSNirmoy Das 	 */
41842a71bbaSNirmoy Das 	lockdep_assert_not_held(&gt->mcr_lock);
41942a71bbaSNirmoy Das 
42042a71bbaSNirmoy Das 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70))
42142a71bbaSNirmoy Das 		intel_uncore_write_fw(gt->uncore, MTL_STEER_SEMAPHORE, 0x1);
42242a71bbaSNirmoy Das }
42342a71bbaSNirmoy Das 
42442a71bbaSNirmoy Das /**
4253fe6c7f5SMatt Roper  * intel_gt_mcr_read - read a specific instance of an MCR register
4263fe6c7f5SMatt Roper  * @gt: GT structure
4273fe6c7f5SMatt Roper  * @reg: the MCR register to read
4283fe6c7f5SMatt Roper  * @group: the MCR group
4293fe6c7f5SMatt Roper  * @instance: the MCR instance
4303fe6c7f5SMatt Roper  *
4314186e218SMatt Roper  * Context: Takes and releases gt->mcr_lock
4324186e218SMatt Roper  *
4333fe6c7f5SMatt Roper  * Returns the value read from an MCR register after steering toward a specific
4343fe6c7f5SMatt Roper  * group/instance.
4353fe6c7f5SMatt Roper  */
intel_gt_mcr_read(struct intel_gt * gt,i915_mcr_reg_t reg,int group,int instance)4363fe6c7f5SMatt Roper u32 intel_gt_mcr_read(struct intel_gt *gt,
43758bc2453SMatt Roper 		      i915_mcr_reg_t reg,
4383fe6c7f5SMatt Roper 		      int group, int instance)
439e7858254SMatt Roper {
4408d9f7d25SMatt Roper 	return rw_with_mcr_steering(gt, reg, FW_REG_READ, group, instance, 0);
441e7858254SMatt Roper }
442e7858254SMatt Roper 
443e7858254SMatt Roper /**
4443fe6c7f5SMatt Roper  * intel_gt_mcr_unicast_write - write a specific instance of an MCR register
4453fe6c7f5SMatt Roper  * @gt: GT structure
4463fe6c7f5SMatt Roper  * @reg: the MCR register to write
4473fe6c7f5SMatt Roper  * @value: value to write
4483fe6c7f5SMatt Roper  * @group: the MCR group
4493fe6c7f5SMatt Roper  * @instance: the MCR instance
4503fe6c7f5SMatt Roper  *
4513fe6c7f5SMatt Roper  * Write an MCR register in unicast mode after steering toward a specific
4523fe6c7f5SMatt Roper  * group/instance.
4534186e218SMatt Roper  *
4544186e218SMatt Roper  * Context: Calls a function that takes and releases gt->mcr_lock
4553fe6c7f5SMatt Roper  */
intel_gt_mcr_unicast_write(struct intel_gt * gt,i915_mcr_reg_t reg,u32 value,int group,int instance)45658bc2453SMatt Roper void intel_gt_mcr_unicast_write(struct intel_gt *gt, i915_mcr_reg_t reg, u32 value,
4573fe6c7f5SMatt Roper 				int group, int instance)
4583fe6c7f5SMatt Roper {
4598d9f7d25SMatt Roper 	rw_with_mcr_steering(gt, reg, FW_REG_WRITE, group, instance, value);
4603fe6c7f5SMatt Roper }
4613fe6c7f5SMatt Roper 
4623fe6c7f5SMatt Roper /**
4633fe6c7f5SMatt Roper  * intel_gt_mcr_multicast_write - write a value to all instances of an MCR register
4643fe6c7f5SMatt Roper  * @gt: GT structure
4653fe6c7f5SMatt Roper  * @reg: the MCR register to write
4663fe6c7f5SMatt Roper  * @value: value to write
4673fe6c7f5SMatt Roper  *
4683fe6c7f5SMatt Roper  * Write an MCR register in multicast mode to update all instances.
4694186e218SMatt Roper  *
4704186e218SMatt Roper  * Context: Takes and releases gt->mcr_lock
4713fe6c7f5SMatt Roper  */
intel_gt_mcr_multicast_write(struct intel_gt * gt,i915_mcr_reg_t reg,u32 value)4723fe6c7f5SMatt Roper void intel_gt_mcr_multicast_write(struct intel_gt *gt,
47358bc2453SMatt Roper 				  i915_mcr_reg_t reg, u32 value)
4743fe6c7f5SMatt Roper {
4754186e218SMatt Roper 	unsigned long flags;
4764186e218SMatt Roper 
4774186e218SMatt Roper 	intel_gt_mcr_lock(gt, &flags);
4784186e218SMatt Roper 
479f32898c9SMatt Roper 	/*
480f32898c9SMatt Roper 	 * Ensure we have multicast behavior, just in case some non-i915 agent
481f32898c9SMatt Roper 	 * left the hardware in unicast mode.
482f32898c9SMatt Roper 	 */
483f32898c9SMatt Roper 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70))
484f32898c9SMatt Roper 		intel_uncore_write_fw(gt->uncore, MTL_MCR_SELECTOR, GEN11_MCR_MULTICAST);
485f32898c9SMatt Roper 
48658bc2453SMatt Roper 	intel_uncore_write(gt->uncore, mcr_reg_cast(reg), value);
4874186e218SMatt Roper 
4884186e218SMatt Roper 	intel_gt_mcr_unlock(gt, flags);
4893fe6c7f5SMatt Roper }
4903fe6c7f5SMatt Roper 
4913fe6c7f5SMatt Roper /**
4923fe6c7f5SMatt Roper  * intel_gt_mcr_multicast_write_fw - write a value to all instances of an MCR register
4933fe6c7f5SMatt Roper  * @gt: GT structure
4943fe6c7f5SMatt Roper  * @reg: the MCR register to write
4953fe6c7f5SMatt Roper  * @value: value to write
4963fe6c7f5SMatt Roper  *
4973fe6c7f5SMatt Roper  * Write an MCR register in multicast mode to update all instances.  This
4983fe6c7f5SMatt Roper  * function assumes the caller is already holding any necessary forcewake
4993fe6c7f5SMatt Roper  * domains; use intel_gt_mcr_multicast_write() in cases where forcewake should
5003fe6c7f5SMatt Roper  * be obtained automatically.
5014186e218SMatt Roper  *
5024186e218SMatt Roper  * Context: The caller must hold gt->mcr_lock.
5033fe6c7f5SMatt Roper  */
intel_gt_mcr_multicast_write_fw(struct intel_gt * gt,i915_mcr_reg_t reg,u32 value)50458bc2453SMatt Roper void intel_gt_mcr_multicast_write_fw(struct intel_gt *gt, i915_mcr_reg_t reg, u32 value)
5053fe6c7f5SMatt Roper {
5064186e218SMatt Roper 	lockdep_assert_held(&gt->mcr_lock);
5074186e218SMatt Roper 
508f32898c9SMatt Roper 	/*
509f32898c9SMatt Roper 	 * Ensure we have multicast behavior, just in case some non-i915 agent
510f32898c9SMatt Roper 	 * left the hardware in unicast mode.
511f32898c9SMatt Roper 	 */
512f32898c9SMatt Roper 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70))
513f32898c9SMatt Roper 		intel_uncore_write_fw(gt->uncore, MTL_MCR_SELECTOR, GEN11_MCR_MULTICAST);
514f32898c9SMatt Roper 
51558bc2453SMatt Roper 	intel_uncore_write_fw(gt->uncore, mcr_reg_cast(reg), value);
5163fe6c7f5SMatt Roper }
5173fe6c7f5SMatt Roper 
518851435ecSMatt Roper /**
519851435ecSMatt Roper  * intel_gt_mcr_multicast_rmw - Performs a multicast RMW operations
520851435ecSMatt Roper  * @gt: GT structure
521851435ecSMatt Roper  * @reg: the MCR register to read and write
522851435ecSMatt Roper  * @clear: bits to clear during RMW
523851435ecSMatt Roper  * @set: bits to set during RMW
524851435ecSMatt Roper  *
525851435ecSMatt Roper  * Performs a read-modify-write on an MCR register in a multicast manner.
526851435ecSMatt Roper  * This operation only makes sense on MCR registers where all instances are
527851435ecSMatt Roper  * expected to have the same value.  The read will target any non-terminated
528851435ecSMatt Roper  * instance and the write will be applied to all instances.
529851435ecSMatt Roper  *
530851435ecSMatt Roper  * This function assumes the caller is already holding any necessary forcewake
531851435ecSMatt Roper  * domains; use intel_gt_mcr_multicast_rmw() in cases where forcewake should
532851435ecSMatt Roper  * be obtained automatically.
533851435ecSMatt Roper  *
5344186e218SMatt Roper  * Context: Calls functions that take and release gt->mcr_lock
5354186e218SMatt Roper  *
536851435ecSMatt Roper  * Returns the old (unmodified) value read.
537851435ecSMatt Roper  */
intel_gt_mcr_multicast_rmw(struct intel_gt * gt,i915_mcr_reg_t reg,u32 clear,u32 set)53858bc2453SMatt Roper u32 intel_gt_mcr_multicast_rmw(struct intel_gt *gt, i915_mcr_reg_t reg,
539851435ecSMatt Roper 			       u32 clear, u32 set)
540851435ecSMatt Roper {
541851435ecSMatt Roper 	u32 val = intel_gt_mcr_read_any(gt, reg);
542851435ecSMatt Roper 
543851435ecSMatt Roper 	intel_gt_mcr_multicast_write(gt, reg, (val & ~clear) | set);
544851435ecSMatt Roper 
545851435ecSMatt Roper 	return val;
546851435ecSMatt Roper }
547851435ecSMatt Roper 
5483fe6c7f5SMatt Roper /*
5493fe6c7f5SMatt Roper  * reg_needs_read_steering - determine whether a register read requires
5503fe6c7f5SMatt Roper  *     explicit steering
551e7858254SMatt Roper  * @gt: GT structure
552e7858254SMatt Roper  * @reg: the register to check steering requirements for
553e7858254SMatt Roper  * @type: type of multicast steering to check
554e7858254SMatt Roper  *
555e7858254SMatt Roper  * Determines whether @reg needs explicit steering of a specific type for
556e7858254SMatt Roper  * reads.
557e7858254SMatt Roper  *
558e7858254SMatt Roper  * Returns false if @reg does not belong to a register range of the given
559e7858254SMatt Roper  * steering type, or if the default (subslice-based) steering IDs are suitable
560e7858254SMatt Roper  * for @type steering too.
561e7858254SMatt Roper  */
reg_needs_read_steering(struct intel_gt * gt,i915_mcr_reg_t reg,enum intel_steering_type type)5623fe6c7f5SMatt Roper static bool reg_needs_read_steering(struct intel_gt *gt,
56358bc2453SMatt Roper 				    i915_mcr_reg_t reg,
564e7858254SMatt Roper 				    enum intel_steering_type type)
565e7858254SMatt Roper {
566d6683bbeSMatt Roper 	u32 offset = i915_mmio_reg_offset(reg);
567e7858254SMatt Roper 	const struct intel_mmio_range *entry;
568e7858254SMatt Roper 
5693fe6c7f5SMatt Roper 	if (likely(!gt->steering_table[type]))
570e7858254SMatt Roper 		return false;
571e7858254SMatt Roper 
572d6683bbeSMatt Roper 	if (IS_GSI_REG(offset))
573d6683bbeSMatt Roper 		offset += gt->uncore->gsi_offset;
574d6683bbeSMatt Roper 
575e7858254SMatt Roper 	for (entry = gt->steering_table[type]; entry->end; entry++) {
576e7858254SMatt Roper 		if (offset >= entry->start && offset <= entry->end)
577e7858254SMatt Roper 			return true;
578e7858254SMatt Roper 	}
579e7858254SMatt Roper 
580e7858254SMatt Roper 	return false;
581e7858254SMatt Roper }
582e7858254SMatt Roper 
5833fe6c7f5SMatt Roper /*
5843fe6c7f5SMatt Roper  * get_nonterminated_steering - determines valid IDs for a class of MCR steering
585e7858254SMatt Roper  * @gt: GT structure
586e7858254SMatt Roper  * @type: multicast register type
5873fe6c7f5SMatt Roper  * @group: Group ID returned
5883fe6c7f5SMatt Roper  * @instance: Instance ID returned
589e7858254SMatt Roper  *
5903fe6c7f5SMatt Roper  * Determines group and instance values that will steer reads of the specified
5913fe6c7f5SMatt Roper  * MCR class to a non-terminated instance.
592e7858254SMatt Roper  */
get_nonterminated_steering(struct intel_gt * gt,enum intel_steering_type type,u8 * group,u8 * instance)5933fe6c7f5SMatt Roper static void get_nonterminated_steering(struct intel_gt *gt,
594e7858254SMatt Roper 				       enum intel_steering_type type,
5953fe6c7f5SMatt Roper 				       u8 *group, u8 *instance)
596e7858254SMatt Roper {
597f32898c9SMatt Roper 	u32 dss;
598f32898c9SMatt Roper 
599e7858254SMatt Roper 	switch (type) {
600e7858254SMatt Roper 	case L3BANK:
6013fe6c7f5SMatt Roper 		*group = 0;		/* unused */
6023fe6c7f5SMatt Roper 		*instance = __ffs(gt->info.l3bank_mask);
603e7858254SMatt Roper 		break;
604e7858254SMatt Roper 	case MSLICE:
605e7858254SMatt Roper 		GEM_WARN_ON(!HAS_MSLICE_STEERING(gt->i915));
6063fe6c7f5SMatt Roper 		*group = __ffs(gt->info.mslice_mask);
6073fe6c7f5SMatt Roper 		*instance = 0;	/* unused */
608e7858254SMatt Roper 		break;
609e7858254SMatt Roper 	case LNCF:
610e7858254SMatt Roper 		/*
611e7858254SMatt Roper 		 * An LNCF is always present if its mslice is present, so we
612e7858254SMatt Roper 		 * can safely just steer to LNCF 0 in all cases.
613e7858254SMatt Roper 		 */
614e7858254SMatt Roper 		GEM_WARN_ON(!HAS_MSLICE_STEERING(gt->i915));
6153fe6c7f5SMatt Roper 		*group = __ffs(gt->info.mslice_mask) << 1;
6163fe6c7f5SMatt Roper 		*instance = 0;	/* unused */
617e7858254SMatt Roper 		break;
61807a70f38SMatt Roper 	case GAM:
61907a70f38SMatt Roper 		*group = IS_DG2(gt->i915) ? 1 : 0;
62007a70f38SMatt Roper 		*instance = 0;
62107a70f38SMatt Roper 		break;
622f32898c9SMatt Roper 	case DSS:
623f32898c9SMatt Roper 		dss = intel_sseu_find_first_xehp_dss(&gt->info.sseu, 0, 0);
624f32898c9SMatt Roper 		*group = dss / GEN_DSS_PER_GSLICE;
625f32898c9SMatt Roper 		*instance = dss % GEN_DSS_PER_GSLICE;
626f32898c9SMatt Roper 		break;
627e7858254SMatt Roper 	case INSTANCE0:
628e7858254SMatt Roper 		/*
629e7858254SMatt Roper 		 * There are a lot of MCR types for which instance (0, 0)
630e7858254SMatt Roper 		 * will always provide a non-terminated value.
631e7858254SMatt Roper 		 */
6323fe6c7f5SMatt Roper 		*group = 0;
6333fe6c7f5SMatt Roper 		*instance = 0;
634e7858254SMatt Roper 		break;
635a7ec65fcSMatt Roper 	case OADDRM:
636a7ec65fcSMatt Roper 		if ((VDBOX_MASK(gt) | VEBOX_MASK(gt) | gt->info.sfc_mask) & BIT(0))
637a7ec65fcSMatt Roper 			*group = 0;
638a7ec65fcSMatt Roper 		else
639a7ec65fcSMatt Roper 			*group = 1;
640a7ec65fcSMatt Roper 		*instance = 0;
641a7ec65fcSMatt Roper 		break;
642e7858254SMatt Roper 	default:
643e7858254SMatt Roper 		MISSING_CASE(type);
6443fe6c7f5SMatt Roper 		*group = 0;
6453fe6c7f5SMatt Roper 		*instance = 0;
646e7858254SMatt Roper 	}
647e7858254SMatt Roper }
648e7858254SMatt Roper 
649e7858254SMatt Roper /**
6503fe6c7f5SMatt Roper  * intel_gt_mcr_get_nonterminated_steering - find group/instance values that
6513fe6c7f5SMatt Roper  *    will steer a register to a non-terminated instance
652e7858254SMatt Roper  * @gt: GT structure
653e7858254SMatt Roper  * @reg: register for which the steering is required
6543fe6c7f5SMatt Roper  * @group: return variable for group steering
6553fe6c7f5SMatt Roper  * @instance: return variable for instance steering
656e7858254SMatt Roper  *
6573fe6c7f5SMatt Roper  * This function returns a group/instance pair that is guaranteed to work for
658e7858254SMatt Roper  * read steering of the given register. Note that a value will be returned even
659e7858254SMatt Roper  * if the register is not replicated and therefore does not actually require
660e7858254SMatt Roper  * steering.
661e7858254SMatt Roper  */
intel_gt_mcr_get_nonterminated_steering(struct intel_gt * gt,i915_mcr_reg_t reg,u8 * group,u8 * instance)6623fe6c7f5SMatt Roper void intel_gt_mcr_get_nonterminated_steering(struct intel_gt *gt,
66358bc2453SMatt Roper 					     i915_mcr_reg_t reg,
6643fe6c7f5SMatt Roper 					     u8 *group, u8 *instance)
665e7858254SMatt Roper {
666e7858254SMatt Roper 	int type;
667e7858254SMatt Roper 
668e7858254SMatt Roper 	for (type = 0; type < NUM_STEERING_TYPES; type++) {
6693fe6c7f5SMatt Roper 		if (reg_needs_read_steering(gt, reg, type)) {
6703fe6c7f5SMatt Roper 			get_nonterminated_steering(gt, type, group, instance);
671e7858254SMatt Roper 			return;
672e7858254SMatt Roper 		}
673e7858254SMatt Roper 	}
674e7858254SMatt Roper 
6753fe6c7f5SMatt Roper 	*group = gt->default_steering.groupid;
6763fe6c7f5SMatt Roper 	*instance = gt->default_steering.instanceid;
677e7858254SMatt Roper }
678e7858254SMatt Roper 
679e7858254SMatt Roper /**
6803fe6c7f5SMatt Roper  * intel_gt_mcr_read_any_fw - reads one instance of an MCR register
681e7858254SMatt Roper  * @gt: GT structure
682e7858254SMatt Roper  * @reg: register to read
683e7858254SMatt Roper  *
6843fe6c7f5SMatt Roper  * Reads a GT MCR register.  The read will be steered to a non-terminated
6853fe6c7f5SMatt Roper  * instance (i.e., one that isn't fused off or powered down by power gating).
6863fe6c7f5SMatt Roper  * This function assumes the caller is already holding any necessary forcewake
6873fe6c7f5SMatt Roper  * domains; use intel_gt_mcr_read_any() in cases where forcewake should be
6883fe6c7f5SMatt Roper  * obtained automatically.
689e7858254SMatt Roper  *
6904186e218SMatt Roper  * Context: The caller must hold gt->mcr_lock.
6914186e218SMatt Roper  *
6923fe6c7f5SMatt Roper  * Returns the value from a non-terminated instance of @reg.
693e7858254SMatt Roper  */
intel_gt_mcr_read_any_fw(struct intel_gt * gt,i915_mcr_reg_t reg)69458bc2453SMatt Roper u32 intel_gt_mcr_read_any_fw(struct intel_gt *gt, i915_mcr_reg_t reg)
695e7858254SMatt Roper {
696e7858254SMatt Roper 	int type;
6973fe6c7f5SMatt Roper 	u8 group, instance;
698e7858254SMatt Roper 
6994186e218SMatt Roper 	lockdep_assert_held(&gt->mcr_lock);
7004186e218SMatt Roper 
701e7858254SMatt Roper 	for (type = 0; type < NUM_STEERING_TYPES; type++) {
7023fe6c7f5SMatt Roper 		if (reg_needs_read_steering(gt, reg, type)) {
7033fe6c7f5SMatt Roper 			get_nonterminated_steering(gt, type, &group, &instance);
7048d9f7d25SMatt Roper 			return rw_with_mcr_steering_fw(gt, reg,
7053fe6c7f5SMatt Roper 						       FW_REG_READ,
7063fe6c7f5SMatt Roper 						       group, instance, 0);
707e7858254SMatt Roper 		}
708e7858254SMatt Roper 	}
709e7858254SMatt Roper 
71058bc2453SMatt Roper 	return intel_uncore_read_fw(gt->uncore, mcr_reg_cast(reg));
711e7858254SMatt Roper }
712e7858254SMatt Roper 
7133fe6c7f5SMatt Roper /**
7143fe6c7f5SMatt Roper  * intel_gt_mcr_read_any - reads one instance of an MCR register
7153fe6c7f5SMatt Roper  * @gt: GT structure
7163fe6c7f5SMatt Roper  * @reg: register to read
7173fe6c7f5SMatt Roper  *
7183fe6c7f5SMatt Roper  * Reads a GT MCR register.  The read will be steered to a non-terminated
7193fe6c7f5SMatt Roper  * instance (i.e., one that isn't fused off or powered down by power gating).
7203fe6c7f5SMatt Roper  *
7214186e218SMatt Roper  * Context: Calls a function that takes and releases gt->mcr_lock.
7224186e218SMatt Roper  *
7233fe6c7f5SMatt Roper  * Returns the value from a non-terminated instance of @reg.
7243fe6c7f5SMatt Roper  */
intel_gt_mcr_read_any(struct intel_gt * gt,i915_mcr_reg_t reg)72558bc2453SMatt Roper u32 intel_gt_mcr_read_any(struct intel_gt *gt, i915_mcr_reg_t reg)
726e7858254SMatt Roper {
727e7858254SMatt Roper 	int type;
7283fe6c7f5SMatt Roper 	u8 group, instance;
729e7858254SMatt Roper 
730e7858254SMatt Roper 	for (type = 0; type < NUM_STEERING_TYPES; type++) {
7313fe6c7f5SMatt Roper 		if (reg_needs_read_steering(gt, reg, type)) {
7323fe6c7f5SMatt Roper 			get_nonterminated_steering(gt, type, &group, &instance);
7338d9f7d25SMatt Roper 			return rw_with_mcr_steering(gt, reg,
7343fe6c7f5SMatt Roper 						    FW_REG_READ,
7353fe6c7f5SMatt Roper 						    group, instance, 0);
736e7858254SMatt Roper 		}
737e7858254SMatt Roper 	}
738e7858254SMatt Roper 
73958bc2453SMatt Roper 	return intel_uncore_read(gt->uncore, mcr_reg_cast(reg));
740e7858254SMatt Roper }
741e7858254SMatt Roper 
report_steering_type(struct drm_printer * p,struct intel_gt * gt,enum intel_steering_type type,bool dump_table)742e7858254SMatt Roper static void report_steering_type(struct drm_printer *p,
743e7858254SMatt Roper 				 struct intel_gt *gt,
744e7858254SMatt Roper 				 enum intel_steering_type type,
745e7858254SMatt Roper 				 bool dump_table)
746e7858254SMatt Roper {
747e7858254SMatt Roper 	const struct intel_mmio_range *entry;
7483fe6c7f5SMatt Roper 	u8 group, instance;
749e7858254SMatt Roper 
750e7858254SMatt Roper 	BUILD_BUG_ON(ARRAY_SIZE(intel_steering_types) != NUM_STEERING_TYPES);
751e7858254SMatt Roper 
752e7858254SMatt Roper 	if (!gt->steering_table[type]) {
753e7858254SMatt Roper 		drm_printf(p, "%s steering: uses default steering\n",
754e7858254SMatt Roper 			   intel_steering_types[type]);
755e7858254SMatt Roper 		return;
756e7858254SMatt Roper 	}
757e7858254SMatt Roper 
7583fe6c7f5SMatt Roper 	get_nonterminated_steering(gt, type, &group, &instance);
7593fe6c7f5SMatt Roper 	drm_printf(p, "%s steering: group=0x%x, instance=0x%x\n",
7603fe6c7f5SMatt Roper 		   intel_steering_types[type], group, instance);
761e7858254SMatt Roper 
762e7858254SMatt Roper 	if (!dump_table)
763e7858254SMatt Roper 		return;
764e7858254SMatt Roper 
765e7858254SMatt Roper 	for (entry = gt->steering_table[type]; entry->end; entry++)
766e7858254SMatt Roper 		drm_printf(p, "\t0x%06x - 0x%06x\n", entry->start, entry->end);
767e7858254SMatt Roper }
768e7858254SMatt Roper 
intel_gt_mcr_report_steering(struct drm_printer * p,struct intel_gt * gt,bool dump_table)7693fe6c7f5SMatt Roper void intel_gt_mcr_report_steering(struct drm_printer *p, struct intel_gt *gt,
770e7858254SMatt Roper 				  bool dump_table)
771e7858254SMatt Roper {
772f32898c9SMatt Roper 	/*
773f32898c9SMatt Roper 	 * Starting with MTL we no longer have default steering;
774f32898c9SMatt Roper 	 * all ranges are explicitly steered.
775f32898c9SMatt Roper 	 */
776f32898c9SMatt Roper 	if (GRAPHICS_VER_FULL(gt->i915) < IP_VER(12, 70))
7773fe6c7f5SMatt Roper 		drm_printf(p, "Default steering: group=0x%x, instance=0x%x\n",
778e7858254SMatt Roper 			   gt->default_steering.groupid,
779e7858254SMatt Roper 			   gt->default_steering.instanceid);
780e7858254SMatt Roper 
781f32898c9SMatt Roper 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 70)) {
782f32898c9SMatt Roper 		for (int i = 0; i < NUM_STEERING_TYPES; i++)
783f32898c9SMatt Roper 			if (gt->steering_table[i])
784f32898c9SMatt Roper 				report_steering_type(p, gt, i, dump_table);
785e7858254SMatt Roper 	} else if (HAS_MSLICE_STEERING(gt->i915)) {
786e7858254SMatt Roper 		report_steering_type(p, gt, MSLICE, dump_table);
787e7858254SMatt Roper 		report_steering_type(p, gt, LNCF, dump_table);
788e7858254SMatt Roper 	}
789e7858254SMatt Roper }
790e7858254SMatt Roper 
7919a92732fSMatt Roper /**
7929a92732fSMatt Roper  * intel_gt_mcr_get_ss_steering - returns the group/instance steering for a SS
7939a92732fSMatt Roper  * @gt: GT structure
7949a92732fSMatt Roper  * @dss: DSS ID to obtain steering for
7959a92732fSMatt Roper  * @group: pointer to storage for steering group ID
7969a92732fSMatt Roper  * @instance: pointer to storage for steering instance ID
7979a92732fSMatt Roper  *
7989a92732fSMatt Roper  * Returns the steering IDs (via the @group and @instance parameters) that
7999a92732fSMatt Roper  * correspond to a specific subslice/DSS ID.
8009a92732fSMatt Roper  */
intel_gt_mcr_get_ss_steering(struct intel_gt * gt,unsigned int dss,unsigned int * group,unsigned int * instance)8019a92732fSMatt Roper void intel_gt_mcr_get_ss_steering(struct intel_gt *gt, unsigned int dss,
8029a92732fSMatt Roper 				   unsigned int *group, unsigned int *instance)
8039a92732fSMatt Roper {
804*326e30e4SLucas De Marchi 	if (GRAPHICS_VER_FULL(gt->i915) >= IP_VER(12, 55)) {
8059a92732fSMatt Roper 		*group = dss / GEN_DSS_PER_GSLICE;
8069a92732fSMatt Roper 		*instance = dss % GEN_DSS_PER_GSLICE;
8079a92732fSMatt Roper 	} else {
808a5e4a538SMatt Roper 		*group = dss / GEN_MAX_SS_PER_HSW_SLICE;
8099a92732fSMatt Roper 		*instance = dss % GEN_MAX_SS_PER_HSW_SLICE;
8109a92732fSMatt Roper 		return;
8119a92732fSMatt Roper 	}
8129a92732fSMatt Roper }
8133068bec8SMatt Roper 
8143068bec8SMatt Roper /**
81503b713d0SMatt Roper  * intel_gt_mcr_wait_for_reg - wait until MCR register matches expected state
8163068bec8SMatt Roper  * @gt: GT structure
8173068bec8SMatt Roper  * @reg: the register to read
8183068bec8SMatt Roper  * @mask: mask to apply to register value
8193068bec8SMatt Roper  * @value: value to wait for
8203068bec8SMatt Roper  * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait
8213068bec8SMatt Roper  * @slow_timeout_ms: slow timeout in millisecond
8223068bec8SMatt Roper  *
8233068bec8SMatt Roper  * This routine waits until the target register @reg contains the expected
8243068bec8SMatt Roper  * @value after applying the @mask, i.e. it waits until ::
8253068bec8SMatt Roper  *
8263068bec8SMatt Roper  *     (intel_gt_mcr_read_any_fw(gt, reg) & mask) == value
8273068bec8SMatt Roper  *
8283068bec8SMatt Roper  * Otherwise, the wait will timeout after @slow_timeout_ms milliseconds.
8293068bec8SMatt Roper  * For atomic context @slow_timeout_ms must be zero and @fast_timeout_us
8303068bec8SMatt Roper  * must be not larger than 20,0000 microseconds.
8313068bec8SMatt Roper  *
8323068bec8SMatt Roper  * This function is basically an MCR-friendly version of
8333068bec8SMatt Roper  * __intel_wait_for_register_fw().  Generally this function will only be used
8343068bec8SMatt Roper  * on GAM registers which are a bit special --- although they're MCR registers,
8353068bec8SMatt Roper  * reads (e.g., waiting for status updates) are always directed to the primary
8363068bec8SMatt Roper  * instance.
8373068bec8SMatt Roper  *
8383068bec8SMatt Roper  * Note that this routine assumes the caller holds forcewake asserted, it is
8393068bec8SMatt Roper  * not suitable for very long waits.
8403068bec8SMatt Roper  *
8414186e218SMatt Roper  * Context: Calls a function that takes and releases gt->mcr_lock
8423068bec8SMatt Roper  * Return: 0 if the register matches the desired condition, or -ETIMEDOUT.
8433068bec8SMatt Roper  */
intel_gt_mcr_wait_for_reg(struct intel_gt * gt,i915_mcr_reg_t reg,u32 mask,u32 value,unsigned int fast_timeout_us,unsigned int slow_timeout_ms)844192bb40fSMatt Roper int intel_gt_mcr_wait_for_reg(struct intel_gt *gt,
84558bc2453SMatt Roper 			      i915_mcr_reg_t reg,
8463068bec8SMatt Roper 			      u32 mask,
8473068bec8SMatt Roper 			      u32 value,
8483068bec8SMatt Roper 			      unsigned int fast_timeout_us,
8493068bec8SMatt Roper 			      unsigned int slow_timeout_ms)
8503068bec8SMatt Roper {
8513068bec8SMatt Roper 	int ret;
8523068bec8SMatt Roper 
8534186e218SMatt Roper 	lockdep_assert_not_held(&gt->mcr_lock);
854192bb40fSMatt Roper 
855192bb40fSMatt Roper #define done ((intel_gt_mcr_read_any(gt, reg) & mask) == value)
856192bb40fSMatt Roper 
8573068bec8SMatt Roper 	/* Catch any overuse of this function */
8583068bec8SMatt Roper 	might_sleep_if(slow_timeout_ms);
8593068bec8SMatt Roper 	GEM_BUG_ON(fast_timeout_us > 20000);
8603068bec8SMatt Roper 	GEM_BUG_ON(!fast_timeout_us && !slow_timeout_ms);
8613068bec8SMatt Roper 
8623068bec8SMatt Roper 	ret = -ETIMEDOUT;
8633068bec8SMatt Roper 	if (fast_timeout_us && fast_timeout_us <= 20000)
8643068bec8SMatt Roper 		ret = _wait_for_atomic(done, fast_timeout_us, 0);
8653068bec8SMatt Roper 	if (ret && slow_timeout_ms)
8663068bec8SMatt Roper 		ret = wait_for(done, slow_timeout_ms);
8673068bec8SMatt Roper 
8683068bec8SMatt Roper 	return ret;
8693068bec8SMatt Roper #undef done
8703068bec8SMatt Roper }
871