blob: 8ae67954563c6a1f798490710237075e61b439f4 [file] [log] [blame]
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +01001/*
2 * Copyright © 2016 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 */
24
25#include "i915_drv.h"
26#include "intel_uc.h"
27
Arkadiusz Hiler413e8fd2016-11-25 18:59:36 +010028void intel_uc_init_early(struct drm_i915_private *dev_priv)
29{
30 mutex_init(&dev_priv->guc.send_mutex);
31}
32
Arkadiusz Hiler2d803c22016-11-25 18:59:35 +010033/*
34 * Read GuC command/status register (SOFT_SCRATCH_0)
35 * Return true if it contains a response rather than a command
36 */
37bool intel_guc_recv(struct drm_i915_private *dev_priv, u32 *status)
38{
39 u32 val = I915_READ(SOFT_SCRATCH(0));
40 *status = val;
41 return INTEL_GUC_RECV_IS_RESPONSE(val);
42}
43
44int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
45{
46 struct drm_i915_private *dev_priv = guc_to_i915(guc);
47 u32 status;
48 int i;
49 int ret;
50
51 if (WARN_ON(len < 1 || len > 15))
52 return -EINVAL;
53
54 mutex_lock(&guc->send_mutex);
55 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
56
57 dev_priv->guc.action_count += 1;
58 dev_priv->guc.action_cmd = action[0];
59
60 for (i = 0; i < len; i++)
61 I915_WRITE(SOFT_SCRATCH(i), action[i]);
62
63 POSTING_READ(SOFT_SCRATCH(i - 1));
64
65 I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER);
66
67 /*
68 * Fast commands should complete in less than 10us, so sample quickly
69 * up to that length of time, then switch to a slower sleep-wait loop.
70 * No inte_guc_send command should ever take longer than 10ms.
71 */
72 ret = wait_for_us(intel_guc_recv(dev_priv, &status), 10);
73 if (ret)
74 ret = wait_for(intel_guc_recv(dev_priv, &status), 10);
75 if (status != INTEL_GUC_STATUS_SUCCESS) {
76 /*
77 * Either the GuC explicitly returned an error (which
78 * we convert to -EIO here) or no response at all was
79 * received within the timeout limit (-ETIMEDOUT)
80 */
81 if (ret != -ETIMEDOUT)
82 ret = -EIO;
83
84 DRM_WARN("INTEL_GUC_SEND: Action 0x%X failed;"
85 " ret=%d status=0x%08X response=0x%08X\n",
86 action[0], ret, status, I915_READ(SOFT_SCRATCH(15)));
87
88 dev_priv->guc.action_fail += 1;
89 dev_priv->guc.action_err = ret;
90 }
91 dev_priv->guc.action_status = status;
92
93 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
94 mutex_unlock(&guc->send_mutex);
95
96 return ret;
97}
98
99int intel_guc_sample_forcewake(struct intel_guc *guc)
100{
101 struct drm_i915_private *dev_priv = guc_to_i915(guc);
102 u32 action[2];
103
104 action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE;
105 /* WaRsDisableCoarsePowerGating:skl,bxt */
106 if (!intel_enable_rc6() || NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
107 action[1] = 0;
108 else
109 /* bit 0 and 1 are for Render and Media domain separately */
110 action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA;
111
112 return intel_guc_send(guc, action, ARRAY_SIZE(action));
113}
114
115int intel_guc_log_flush_complete(struct intel_guc *guc)
116{
117 u32 action[] = { INTEL_GUC_ACTION_LOG_BUFFER_FILE_FLUSH_COMPLETE };
118
119 return intel_guc_send(guc, action, ARRAY_SIZE(action));
120}
121
122int intel_guc_log_flush(struct intel_guc *guc)
123{
124 u32 action[] = {
125 INTEL_GUC_ACTION_FORCE_LOG_BUFFER_FLUSH,
126 0
127 };
128
129 return intel_guc_send(guc, action, ARRAY_SIZE(action));
130}
131
132int intel_guc_log_control(struct intel_guc *guc, u32 control_val)
133{
134 u32 action[] = {
135 INTEL_GUC_ACTION_UK_LOG_ENABLE_LOGGING,
136 control_val
137 };
138
139 return intel_guc_send(guc, action, ARRAY_SIZE(action));
140}