xref: /dflybsd-src/sys/dev/drm/i915/intel_guc.c (revision 3f2dd94a569761201b5b0a18b2f697f97fe1b9dc)
1*3f2dd94aSFrançois Tigeot /*
2*3f2dd94aSFrançois Tigeot  * Copyright © 2014-2017 Intel Corporation
3*3f2dd94aSFrançois Tigeot  *
4*3f2dd94aSFrançois Tigeot  * Permission is hereby granted, free of charge, to any person obtaining a
5*3f2dd94aSFrançois Tigeot  * copy of this software and associated documentation files (the "Software"),
6*3f2dd94aSFrançois Tigeot  * to deal in the Software without restriction, including without limitation
7*3f2dd94aSFrançois Tigeot  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*3f2dd94aSFrançois Tigeot  * and/or sell copies of the Software, and to permit persons to whom the
9*3f2dd94aSFrançois Tigeot  * Software is furnished to do so, subject to the following conditions:
10*3f2dd94aSFrançois Tigeot  *
11*3f2dd94aSFrançois Tigeot  * The above copyright notice and this permission notice (including the next
12*3f2dd94aSFrançois Tigeot  * paragraph) shall be included in all copies or substantial portions of the
13*3f2dd94aSFrançois Tigeot  * Software.
14*3f2dd94aSFrançois Tigeot  *
15*3f2dd94aSFrançois Tigeot  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*3f2dd94aSFrançois Tigeot  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*3f2dd94aSFrançois Tigeot  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*3f2dd94aSFrançois Tigeot  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*3f2dd94aSFrançois Tigeot  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*3f2dd94aSFrançois Tigeot  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*3f2dd94aSFrançois Tigeot  * IN THE SOFTWARE.
22*3f2dd94aSFrançois Tigeot  *
23*3f2dd94aSFrançois Tigeot  */
24*3f2dd94aSFrançois Tigeot 
25*3f2dd94aSFrançois Tigeot #include "intel_guc.h"
26*3f2dd94aSFrançois Tigeot #include "i915_drv.h"
27*3f2dd94aSFrançois Tigeot 
gen8_guc_raise_irq(struct intel_guc * guc)28*3f2dd94aSFrançois Tigeot static void gen8_guc_raise_irq(struct intel_guc *guc)
29*3f2dd94aSFrançois Tigeot {
30*3f2dd94aSFrançois Tigeot 	struct drm_i915_private *dev_priv = guc_to_i915(guc);
31*3f2dd94aSFrançois Tigeot 
32*3f2dd94aSFrançois Tigeot 	I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER);
33*3f2dd94aSFrançois Tigeot }
34*3f2dd94aSFrançois Tigeot 
guc_send_reg(struct intel_guc * guc,u32 i)35*3f2dd94aSFrançois Tigeot static inline i915_reg_t guc_send_reg(struct intel_guc *guc, u32 i)
36*3f2dd94aSFrançois Tigeot {
37*3f2dd94aSFrançois Tigeot 	GEM_BUG_ON(!guc->send_regs.base);
38*3f2dd94aSFrançois Tigeot 	GEM_BUG_ON(!guc->send_regs.count);
39*3f2dd94aSFrançois Tigeot 	GEM_BUG_ON(i >= guc->send_regs.count);
40*3f2dd94aSFrançois Tigeot 
41*3f2dd94aSFrançois Tigeot 	return _MMIO(guc->send_regs.base + 4 * i);
42*3f2dd94aSFrançois Tigeot }
43*3f2dd94aSFrançois Tigeot 
intel_guc_init_send_regs(struct intel_guc * guc)44*3f2dd94aSFrançois Tigeot void intel_guc_init_send_regs(struct intel_guc *guc)
45*3f2dd94aSFrançois Tigeot {
46*3f2dd94aSFrançois Tigeot 	struct drm_i915_private *dev_priv = guc_to_i915(guc);
47*3f2dd94aSFrançois Tigeot 	enum forcewake_domains fw_domains = 0;
48*3f2dd94aSFrançois Tigeot 	unsigned int i;
49*3f2dd94aSFrançois Tigeot 
50*3f2dd94aSFrançois Tigeot 	guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0));
51*3f2dd94aSFrançois Tigeot 	guc->send_regs.count = SOFT_SCRATCH_COUNT - 1;
52*3f2dd94aSFrançois Tigeot 
53*3f2dd94aSFrançois Tigeot 	for (i = 0; i < guc->send_regs.count; i++) {
54*3f2dd94aSFrançois Tigeot 		fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
55*3f2dd94aSFrançois Tigeot 					guc_send_reg(guc, i),
56*3f2dd94aSFrançois Tigeot 					FW_REG_READ | FW_REG_WRITE);
57*3f2dd94aSFrançois Tigeot 	}
58*3f2dd94aSFrançois Tigeot 	guc->send_regs.fw_domains = fw_domains;
59*3f2dd94aSFrançois Tigeot }
60*3f2dd94aSFrançois Tigeot 
intel_guc_init_early(struct intel_guc * guc)61*3f2dd94aSFrançois Tigeot void intel_guc_init_early(struct intel_guc *guc)
62*3f2dd94aSFrançois Tigeot {
63*3f2dd94aSFrançois Tigeot 	intel_guc_ct_init_early(&guc->ct);
64*3f2dd94aSFrançois Tigeot 
65*3f2dd94aSFrançois Tigeot 	lockinit(&guc->send_mutex, "i9pgsm", 0, LK_CANRECURSE);
66*3f2dd94aSFrançois Tigeot 	guc->send = intel_guc_send_nop;
67*3f2dd94aSFrançois Tigeot 	guc->notify = gen8_guc_raise_irq;
68*3f2dd94aSFrançois Tigeot }
69*3f2dd94aSFrançois Tigeot 
get_gt_type(struct drm_i915_private * dev_priv)70*3f2dd94aSFrançois Tigeot static u32 get_gt_type(struct drm_i915_private *dev_priv)
71*3f2dd94aSFrançois Tigeot {
72*3f2dd94aSFrançois Tigeot 	/* XXX: GT type based on PCI device ID? field seems unused by fw */
73*3f2dd94aSFrançois Tigeot 	return 0;
74*3f2dd94aSFrançois Tigeot }
75*3f2dd94aSFrançois Tigeot 
get_core_family(struct drm_i915_private * dev_priv)76*3f2dd94aSFrançois Tigeot static u32 get_core_family(struct drm_i915_private *dev_priv)
77*3f2dd94aSFrançois Tigeot {
78*3f2dd94aSFrançois Tigeot 	u32 gen = INTEL_GEN(dev_priv);
79*3f2dd94aSFrançois Tigeot 
80*3f2dd94aSFrançois Tigeot 	switch (gen) {
81*3f2dd94aSFrançois Tigeot 	case 9:
82*3f2dd94aSFrançois Tigeot 		return GUC_CORE_FAMILY_GEN9;
83*3f2dd94aSFrançois Tigeot 
84*3f2dd94aSFrançois Tigeot 	default:
85*3f2dd94aSFrançois Tigeot 		MISSING_CASE(gen);
86*3f2dd94aSFrançois Tigeot 		return GUC_CORE_FAMILY_UNKNOWN;
87*3f2dd94aSFrançois Tigeot 	}
88*3f2dd94aSFrançois Tigeot }
89*3f2dd94aSFrançois Tigeot 
90*3f2dd94aSFrançois Tigeot /*
91*3f2dd94aSFrançois Tigeot  * Initialise the GuC parameter block before starting the firmware
92*3f2dd94aSFrançois Tigeot  * transfer. These parameters are read by the firmware on startup
93*3f2dd94aSFrançois Tigeot  * and cannot be changed thereafter.
94*3f2dd94aSFrançois Tigeot  */
intel_guc_init_params(struct intel_guc * guc)95*3f2dd94aSFrançois Tigeot void intel_guc_init_params(struct intel_guc *guc)
96*3f2dd94aSFrançois Tigeot {
97*3f2dd94aSFrançois Tigeot 	struct drm_i915_private *dev_priv = guc_to_i915(guc);
98*3f2dd94aSFrançois Tigeot 	u32 params[GUC_CTL_MAX_DWORDS];
99*3f2dd94aSFrançois Tigeot 	int i;
100*3f2dd94aSFrançois Tigeot 
101*3f2dd94aSFrançois Tigeot 	memset(params, 0, sizeof(params));
102*3f2dd94aSFrançois Tigeot 
103*3f2dd94aSFrançois Tigeot 	params[GUC_CTL_DEVICE_INFO] |=
104*3f2dd94aSFrançois Tigeot 		(get_gt_type(dev_priv) << GUC_CTL_GT_TYPE_SHIFT) |
105*3f2dd94aSFrançois Tigeot 		(get_core_family(dev_priv) << GUC_CTL_CORE_FAMILY_SHIFT);
106*3f2dd94aSFrançois Tigeot 
107*3f2dd94aSFrançois Tigeot 	/*
108*3f2dd94aSFrançois Tigeot 	 * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one
109*3f2dd94aSFrançois Tigeot 	 * second. This ARAR is calculated by:
110*3f2dd94aSFrançois Tigeot 	 * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10
111*3f2dd94aSFrançois Tigeot 	 */
112*3f2dd94aSFrançois Tigeot 	params[GUC_CTL_ARAT_HIGH] = 0;
113*3f2dd94aSFrançois Tigeot 	params[GUC_CTL_ARAT_LOW] = 100000000;
114*3f2dd94aSFrançois Tigeot 
115*3f2dd94aSFrançois Tigeot 	params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER;
116*3f2dd94aSFrançois Tigeot 
117*3f2dd94aSFrançois Tigeot 	params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER |
118*3f2dd94aSFrançois Tigeot 			GUC_CTL_VCS2_ENABLED;
119*3f2dd94aSFrançois Tigeot 
120*3f2dd94aSFrançois Tigeot 	params[GUC_CTL_LOG_PARAMS] = guc->log.flags;
121*3f2dd94aSFrançois Tigeot 
122*3f2dd94aSFrançois Tigeot 	if (i915_modparams.guc_log_level >= 0) {
123*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_DEBUG] =
124*3f2dd94aSFrançois Tigeot 			i915_modparams.guc_log_level << GUC_LOG_VERBOSITY_SHIFT;
125*3f2dd94aSFrançois Tigeot 	} else {
126*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_DEBUG] = GUC_LOG_DISABLED;
127*3f2dd94aSFrançois Tigeot 	}
128*3f2dd94aSFrançois Tigeot 
129*3f2dd94aSFrançois Tigeot 	/* If GuC submission is enabled, set up additional parameters here */
130*3f2dd94aSFrançois Tigeot 	if (i915_modparams.enable_guc_submission) {
131*3f2dd94aSFrançois Tigeot 		u32 ads = guc_ggtt_offset(guc->ads_vma) >> PAGE_SHIFT;
132*3f2dd94aSFrançois Tigeot 		u32 pgs = guc_ggtt_offset(dev_priv->guc.stage_desc_pool);
133*3f2dd94aSFrançois Tigeot 		u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16;
134*3f2dd94aSFrançois Tigeot 
135*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
136*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
137*3f2dd94aSFrançois Tigeot 
138*3f2dd94aSFrançois Tigeot 		pgs >>= PAGE_SHIFT;
139*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
140*3f2dd94aSFrançois Tigeot 			(ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
141*3f2dd94aSFrançois Tigeot 
142*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS;
143*3f2dd94aSFrançois Tigeot 
144*3f2dd94aSFrançois Tigeot 		/* Unmask this bit to enable the GuC's internal scheduler */
145*3f2dd94aSFrançois Tigeot 		params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER;
146*3f2dd94aSFrançois Tigeot 	}
147*3f2dd94aSFrançois Tigeot 
148*3f2dd94aSFrançois Tigeot 	/*
149*3f2dd94aSFrançois Tigeot 	 * All SOFT_SCRATCH registers are in FORCEWAKE_BLITTER domain and
150*3f2dd94aSFrançois Tigeot 	 * they are power context saved so it's ok to release forcewake
151*3f2dd94aSFrançois Tigeot 	 * when we are done here and take it again at xfer time.
152*3f2dd94aSFrançois Tigeot 	 */
153*3f2dd94aSFrançois Tigeot 	intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER);
154*3f2dd94aSFrançois Tigeot 
155*3f2dd94aSFrançois Tigeot 	I915_WRITE(SOFT_SCRATCH(0), 0);
156*3f2dd94aSFrançois Tigeot 
157*3f2dd94aSFrançois Tigeot 	for (i = 0; i < GUC_CTL_MAX_DWORDS; i++)
158*3f2dd94aSFrançois Tigeot 		I915_WRITE(SOFT_SCRATCH(1 + i), params[i]);
159*3f2dd94aSFrançois Tigeot 
160*3f2dd94aSFrançois Tigeot 	intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER);
161*3f2dd94aSFrançois Tigeot }
162*3f2dd94aSFrançois Tigeot 
intel_guc_send_nop(struct intel_guc * guc,const u32 * action,u32 len)163*3f2dd94aSFrançois Tigeot int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len)
164*3f2dd94aSFrançois Tigeot {
165*3f2dd94aSFrançois Tigeot 	WARN(1, "Unexpected send: action=%#x\n", *action);
166*3f2dd94aSFrançois Tigeot 	return -ENODEV;
167*3f2dd94aSFrançois Tigeot }
168*3f2dd94aSFrançois Tigeot 
169*3f2dd94aSFrançois Tigeot /*
170*3f2dd94aSFrançois Tigeot  * This function implements the MMIO based host to GuC interface.
171*3f2dd94aSFrançois Tigeot  */
intel_guc_send_mmio(struct intel_guc * guc,const u32 * action,u32 len)172*3f2dd94aSFrançois Tigeot int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len)
173*3f2dd94aSFrançois Tigeot {
174*3f2dd94aSFrançois Tigeot 	struct drm_i915_private *dev_priv = guc_to_i915(guc);
175*3f2dd94aSFrançois Tigeot 	u32 status;
176*3f2dd94aSFrançois Tigeot 	int i;
177*3f2dd94aSFrançois Tigeot 	int ret;
178*3f2dd94aSFrançois Tigeot 
179*3f2dd94aSFrançois Tigeot 	GEM_BUG_ON(!len);
180*3f2dd94aSFrançois Tigeot 	GEM_BUG_ON(len > guc->send_regs.count);
181*3f2dd94aSFrançois Tigeot 
182*3f2dd94aSFrançois Tigeot 	/* If CT is available, we expect to use MMIO only during init/fini */
183*3f2dd94aSFrançois Tigeot 	GEM_BUG_ON(HAS_GUC_CT(dev_priv) &&
184*3f2dd94aSFrançois Tigeot 		*action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER &&
185*3f2dd94aSFrançois Tigeot 		*action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER);
186*3f2dd94aSFrançois Tigeot 
187*3f2dd94aSFrançois Tigeot 	mutex_lock(&guc->send_mutex);
188*3f2dd94aSFrançois Tigeot 	intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains);
189*3f2dd94aSFrançois Tigeot 
190*3f2dd94aSFrançois Tigeot 	for (i = 0; i < len; i++)
191*3f2dd94aSFrançois Tigeot 		I915_WRITE(guc_send_reg(guc, i), action[i]);
192*3f2dd94aSFrançois Tigeot 
193*3f2dd94aSFrançois Tigeot 	POSTING_READ(guc_send_reg(guc, i - 1));
194*3f2dd94aSFrançois Tigeot 
195*3f2dd94aSFrançois Tigeot 	intel_guc_notify(guc);
196*3f2dd94aSFrançois Tigeot 
197*3f2dd94aSFrançois Tigeot 	/*
198*3f2dd94aSFrançois Tigeot 	 * No GuC command should ever take longer than 10ms.
199*3f2dd94aSFrançois Tigeot 	 * Fast commands should still complete in 10us.
200*3f2dd94aSFrançois Tigeot 	 */
201*3f2dd94aSFrançois Tigeot 	ret = __intel_wait_for_register_fw(dev_priv,
202*3f2dd94aSFrançois Tigeot 					   guc_send_reg(guc, 0),
203*3f2dd94aSFrançois Tigeot 					   INTEL_GUC_RECV_MASK,
204*3f2dd94aSFrançois Tigeot 					   INTEL_GUC_RECV_MASK,
205*3f2dd94aSFrançois Tigeot 					   10, 10, &status);
206*3f2dd94aSFrançois Tigeot 	if (status != INTEL_GUC_STATUS_SUCCESS) {
207*3f2dd94aSFrançois Tigeot 		/*
208*3f2dd94aSFrançois Tigeot 		 * Either the GuC explicitly returned an error (which
209*3f2dd94aSFrançois Tigeot 		 * we convert to -EIO here) or no response at all was
210*3f2dd94aSFrançois Tigeot 		 * received within the timeout limit (-ETIMEDOUT)
211*3f2dd94aSFrançois Tigeot 		 */
212*3f2dd94aSFrançois Tigeot 		if (ret != -ETIMEDOUT)
213*3f2dd94aSFrançois Tigeot 			ret = -EIO;
214*3f2dd94aSFrançois Tigeot 
215*3f2dd94aSFrançois Tigeot 		DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;"
216*3f2dd94aSFrançois Tigeot 			 " ret=%d status=0x%08X response=0x%08X\n",
217*3f2dd94aSFrançois Tigeot 			 action[0], ret, status, I915_READ(SOFT_SCRATCH(15)));
218*3f2dd94aSFrançois Tigeot 	}
219*3f2dd94aSFrançois Tigeot 
220*3f2dd94aSFrançois Tigeot 	intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains);
221*3f2dd94aSFrançois Tigeot 	mutex_unlock(&guc->send_mutex);
222*3f2dd94aSFrançois Tigeot 
223*3f2dd94aSFrançois Tigeot 	return ret;
224*3f2dd94aSFrançois Tigeot }
225*3f2dd94aSFrançois Tigeot 
intel_guc_sample_forcewake(struct intel_guc * guc)226*3f2dd94aSFrançois Tigeot int intel_guc_sample_forcewake(struct intel_guc *guc)
227*3f2dd94aSFrançois Tigeot {
228*3f2dd94aSFrançois Tigeot 	struct drm_i915_private *dev_priv = guc_to_i915(guc);
229*3f2dd94aSFrançois Tigeot 	u32 action[2];
230*3f2dd94aSFrançois Tigeot 
231*3f2dd94aSFrançois Tigeot 	action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE;
232*3f2dd94aSFrançois Tigeot 	/* WaRsDisableCoarsePowerGating:skl,bxt */
233*3f2dd94aSFrançois Tigeot 	if (!intel_rc6_enabled() ||
234*3f2dd94aSFrançois Tigeot 	    NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
235*3f2dd94aSFrançois Tigeot 		action[1] = 0;
236*3f2dd94aSFrançois Tigeot 	else
237*3f2dd94aSFrançois Tigeot 		/* bit 0 and 1 are for Render and Media domain separately */
238*3f2dd94aSFrançois Tigeot 		action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA;
239*3f2dd94aSFrançois Tigeot 
240*3f2dd94aSFrançois Tigeot 	return intel_guc_send(guc, action, ARRAY_SIZE(action));
241*3f2dd94aSFrançois Tigeot }
242*3f2dd94aSFrançois Tigeot 
243*3f2dd94aSFrançois Tigeot /**
244*3f2dd94aSFrançois Tigeot  * intel_guc_auth_huc() - Send action to GuC to authenticate HuC ucode
245*3f2dd94aSFrançois Tigeot  * @guc: intel_guc structure
246*3f2dd94aSFrançois Tigeot  * @rsa_offset: rsa offset w.r.t ggtt base of huc vma
247*3f2dd94aSFrançois Tigeot  *
248*3f2dd94aSFrançois Tigeot  * Triggers a HuC firmware authentication request to the GuC via intel_guc_send
249*3f2dd94aSFrançois Tigeot  * INTEL_GUC_ACTION_AUTHENTICATE_HUC interface. This function is invoked by
250*3f2dd94aSFrançois Tigeot  * intel_huc_auth().
251*3f2dd94aSFrançois Tigeot  *
252*3f2dd94aSFrançois Tigeot  * Return:	non-zero code on error
253*3f2dd94aSFrançois Tigeot  */
intel_guc_auth_huc(struct intel_guc * guc,u32 rsa_offset)254*3f2dd94aSFrançois Tigeot int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset)
255*3f2dd94aSFrançois Tigeot {
256*3f2dd94aSFrançois Tigeot 	u32 action[] = {
257*3f2dd94aSFrançois Tigeot 		INTEL_GUC_ACTION_AUTHENTICATE_HUC,
258*3f2dd94aSFrançois Tigeot 		rsa_offset
259*3f2dd94aSFrançois Tigeot 	};
260*3f2dd94aSFrançois Tigeot 
261*3f2dd94aSFrançois Tigeot 	return intel_guc_send(guc, action, ARRAY_SIZE(action));
262*3f2dd94aSFrançois Tigeot }
263*3f2dd94aSFrançois Tigeot 
264*3f2dd94aSFrançois Tigeot /**
265*3f2dd94aSFrançois Tigeot  * intel_guc_suspend() - notify GuC entering suspend state
266*3f2dd94aSFrançois Tigeot  * @dev_priv:	i915 device private
267*3f2dd94aSFrançois Tigeot  */
intel_guc_suspend(struct drm_i915_private * dev_priv)268*3f2dd94aSFrançois Tigeot int intel_guc_suspend(struct drm_i915_private *dev_priv)
269*3f2dd94aSFrançois Tigeot {
270*3f2dd94aSFrançois Tigeot 	struct intel_guc *guc = &dev_priv->guc;
271*3f2dd94aSFrançois Tigeot 	struct i915_gem_context *ctx;
272*3f2dd94aSFrançois Tigeot 	u32 data[3];
273*3f2dd94aSFrançois Tigeot 
274*3f2dd94aSFrançois Tigeot 	if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
275*3f2dd94aSFrançois Tigeot 		return 0;
276*3f2dd94aSFrançois Tigeot 
277*3f2dd94aSFrançois Tigeot 	gen9_disable_guc_interrupts(dev_priv);
278*3f2dd94aSFrançois Tigeot 
279*3f2dd94aSFrançois Tigeot 	ctx = dev_priv->kernel_context;
280*3f2dd94aSFrançois Tigeot 
281*3f2dd94aSFrançois Tigeot 	data[0] = INTEL_GUC_ACTION_ENTER_S_STATE;
282*3f2dd94aSFrançois Tigeot 	/* any value greater than GUC_POWER_D0 */
283*3f2dd94aSFrançois Tigeot 	data[1] = GUC_POWER_D1;
284*3f2dd94aSFrançois Tigeot 	/* first page is shared data with GuC */
285*3f2dd94aSFrançois Tigeot 	data[2] = guc_ggtt_offset(ctx->engine[RCS].state) +
286*3f2dd94aSFrançois Tigeot 		  LRC_GUCSHR_PN * PAGE_SIZE;
287*3f2dd94aSFrançois Tigeot 
288*3f2dd94aSFrançois Tigeot 	return intel_guc_send(guc, data, ARRAY_SIZE(data));
289*3f2dd94aSFrançois Tigeot }
290*3f2dd94aSFrançois Tigeot 
291*3f2dd94aSFrançois Tigeot /**
292*3f2dd94aSFrançois Tigeot  * intel_guc_resume() - notify GuC resuming from suspend state
293*3f2dd94aSFrançois Tigeot  * @dev_priv:	i915 device private
294*3f2dd94aSFrançois Tigeot  */
intel_guc_resume(struct drm_i915_private * dev_priv)295*3f2dd94aSFrançois Tigeot int intel_guc_resume(struct drm_i915_private *dev_priv)
296*3f2dd94aSFrançois Tigeot {
297*3f2dd94aSFrançois Tigeot 	struct intel_guc *guc = &dev_priv->guc;
298*3f2dd94aSFrançois Tigeot 	struct i915_gem_context *ctx;
299*3f2dd94aSFrançois Tigeot 	u32 data[3];
300*3f2dd94aSFrançois Tigeot 
301*3f2dd94aSFrançois Tigeot 	if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS)
302*3f2dd94aSFrançois Tigeot 		return 0;
303*3f2dd94aSFrançois Tigeot 
304*3f2dd94aSFrançois Tigeot 	if (i915_modparams.guc_log_level >= 0)
305*3f2dd94aSFrançois Tigeot 		gen9_enable_guc_interrupts(dev_priv);
306*3f2dd94aSFrançois Tigeot 
307*3f2dd94aSFrançois Tigeot 	ctx = dev_priv->kernel_context;
308*3f2dd94aSFrançois Tigeot 
309*3f2dd94aSFrançois Tigeot 	data[0] = INTEL_GUC_ACTION_EXIT_S_STATE;
310*3f2dd94aSFrançois Tigeot 	data[1] = GUC_POWER_D0;
311*3f2dd94aSFrançois Tigeot 	/* first page is shared data with GuC */
312*3f2dd94aSFrançois Tigeot 	data[2] = guc_ggtt_offset(ctx->engine[RCS].state) +
313*3f2dd94aSFrançois Tigeot 		  LRC_GUCSHR_PN * PAGE_SIZE;
314*3f2dd94aSFrançois Tigeot 
315*3f2dd94aSFrançois Tigeot 	return intel_guc_send(guc, data, ARRAY_SIZE(data));
316*3f2dd94aSFrançois Tigeot }
317*3f2dd94aSFrançois Tigeot 
318*3f2dd94aSFrançois Tigeot /**
319*3f2dd94aSFrançois Tigeot  * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage
320*3f2dd94aSFrançois Tigeot  * @guc:	the guc
321*3f2dd94aSFrançois Tigeot  * @size:	size of area to allocate (both virtual space and memory)
322*3f2dd94aSFrançois Tigeot  *
323*3f2dd94aSFrançois Tigeot  * This is a wrapper to create an object for use with the GuC. In order to
324*3f2dd94aSFrançois Tigeot  * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
325*3f2dd94aSFrançois Tigeot  * both some backing storage and a range inside the Global GTT. We must pin
326*3f2dd94aSFrançois Tigeot  * it in the GGTT somewhere other than than [0, GUC_WOPCM_TOP) because that
327*3f2dd94aSFrançois Tigeot  * range is reserved inside GuC.
328*3f2dd94aSFrançois Tigeot  *
329*3f2dd94aSFrançois Tigeot  * Return:	A i915_vma if successful, otherwise an ERR_PTR.
330*3f2dd94aSFrançois Tigeot  */
intel_guc_allocate_vma(struct intel_guc * guc,u32 size)331*3f2dd94aSFrançois Tigeot struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
332*3f2dd94aSFrançois Tigeot {
333*3f2dd94aSFrançois Tigeot 	struct drm_i915_private *dev_priv = guc_to_i915(guc);
334*3f2dd94aSFrançois Tigeot 	struct drm_i915_gem_object *obj;
335*3f2dd94aSFrançois Tigeot 	struct i915_vma *vma;
336*3f2dd94aSFrançois Tigeot 	int ret;
337*3f2dd94aSFrançois Tigeot 
338*3f2dd94aSFrançois Tigeot 	obj = i915_gem_object_create(dev_priv, size);
339*3f2dd94aSFrançois Tigeot 	if (IS_ERR(obj))
340*3f2dd94aSFrançois Tigeot 		return ERR_CAST(obj);
341*3f2dd94aSFrançois Tigeot 
342*3f2dd94aSFrançois Tigeot 	vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
343*3f2dd94aSFrançois Tigeot 	if (IS_ERR(vma))
344*3f2dd94aSFrançois Tigeot 		goto err;
345*3f2dd94aSFrançois Tigeot 
346*3f2dd94aSFrançois Tigeot 	ret = i915_vma_pin(vma, 0, PAGE_SIZE,
347*3f2dd94aSFrançois Tigeot 			   PIN_GLOBAL | PIN_OFFSET_BIAS | GUC_WOPCM_TOP);
348*3f2dd94aSFrançois Tigeot 	if (ret) {
349*3f2dd94aSFrançois Tigeot 		vma = ERR_PTR(ret);
350*3f2dd94aSFrançois Tigeot 		goto err;
351*3f2dd94aSFrançois Tigeot 	}
352*3f2dd94aSFrançois Tigeot 
353*3f2dd94aSFrançois Tigeot 	return vma;
354*3f2dd94aSFrançois Tigeot 
355*3f2dd94aSFrançois Tigeot err:
356*3f2dd94aSFrançois Tigeot 	i915_gem_object_put(obj);
357*3f2dd94aSFrançois Tigeot 	return vma;
358*3f2dd94aSFrançois Tigeot }
359*3f2dd94aSFrançois Tigeot 
intel_guc_wopcm_size(struct drm_i915_private * dev_priv)360*3f2dd94aSFrançois Tigeot u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv)
361*3f2dd94aSFrançois Tigeot {
362*3f2dd94aSFrançois Tigeot 	u32 wopcm_size = GUC_WOPCM_TOP;
363*3f2dd94aSFrançois Tigeot 
364*3f2dd94aSFrançois Tigeot 	/* On BXT, the top of WOPCM is reserved for RC6 context */
365*3f2dd94aSFrançois Tigeot 	if (IS_GEN9_LP(dev_priv))
366*3f2dd94aSFrançois Tigeot 		wopcm_size -= BXT_GUC_WOPCM_RC6_RESERVED;
367*3f2dd94aSFrançois Tigeot 
368*3f2dd94aSFrançois Tigeot 	return wopcm_size;
369*3f2dd94aSFrançois Tigeot }
370