2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 void intel_uc_init_early(struct drm_i915_private
*dev_priv
)
30 mutex_init(&dev_priv
->guc
.send_mutex
);
34 * Read GuC command/status register (SOFT_SCRATCH_0)
35 * Return true if it contains a response rather than a command
37 static bool intel_guc_recv(struct intel_guc
*guc
, u32
*status
)
39 struct drm_i915_private
*dev_priv
= guc_to_i915(guc
);
41 u32 val
= I915_READ(SOFT_SCRATCH(0));
43 return INTEL_GUC_RECV_IS_RESPONSE(val
);
46 int intel_guc_send(struct intel_guc
*guc
, const u32
*action
, u32 len
)
48 struct drm_i915_private
*dev_priv
= guc_to_i915(guc
);
53 if (WARN_ON(len
< 1 || len
> 15))
56 mutex_lock(&guc
->send_mutex
);
57 intel_uncore_forcewake_get(dev_priv
, FORCEWAKE_ALL
);
59 dev_priv
->guc
.action_count
+= 1;
60 dev_priv
->guc
.action_cmd
= action
[0];
62 for (i
= 0; i
< len
; i
++)
63 I915_WRITE(SOFT_SCRATCH(i
), action
[i
]);
65 POSTING_READ(SOFT_SCRATCH(i
- 1));
67 I915_WRITE(GUC_SEND_INTERRUPT
, GUC_SEND_TRIGGER
);
70 * Fast commands should complete in less than 10us, so sample quickly
71 * up to that length of time, then switch to a slower sleep-wait loop.
72 * No inte_guc_send command should ever take longer than 10ms.
74 ret
= wait_for_us(intel_guc_recv(guc
, &status
), 10);
76 ret
= wait_for(intel_guc_recv(guc
, &status
), 10);
77 if (status
!= INTEL_GUC_STATUS_SUCCESS
) {
79 * Either the GuC explicitly returned an error (which
80 * we convert to -EIO here) or no response at all was
81 * received within the timeout limit (-ETIMEDOUT)
83 if (ret
!= -ETIMEDOUT
)
86 DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;"
87 " ret=%d status=0x%08X response=0x%08X\n",
88 action
[0], ret
, status
, I915_READ(SOFT_SCRATCH(15)));
90 dev_priv
->guc
.action_fail
+= 1;
91 dev_priv
->guc
.action_err
= ret
;
93 dev_priv
->guc
.action_status
= status
;
95 intel_uncore_forcewake_put(dev_priv
, FORCEWAKE_ALL
);
96 mutex_unlock(&guc
->send_mutex
);
101 int intel_guc_sample_forcewake(struct intel_guc
*guc
)
103 struct drm_i915_private
*dev_priv
= guc_to_i915(guc
);
106 action
[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE
;
107 /* WaRsDisableCoarsePowerGating:skl,bxt */
108 if (!intel_enable_rc6() || NEEDS_WaRsDisableCoarsePowerGating(dev_priv
))
111 /* bit 0 and 1 are for Render and Media domain separately */
112 action
[1] = GUC_FORCEWAKE_RENDER
| GUC_FORCEWAKE_MEDIA
;
114 return intel_guc_send(guc
, action
, ARRAY_SIZE(action
));