blob: 8f93f5bef8fdbbb63dc235166b308584bd9db57b [file] [log] [blame]
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +00001/*
2 * Copyright © 2014-2017 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 "intel_guc.h"
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -080026#include "intel_guc_ads.h"
Sagar Arun Kamblea2695742017-11-16 19:02:41 +053027#include "intel_guc_submission.h"
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000028#include "i915_drv.h"
29
30static void gen8_guc_raise_irq(struct intel_guc *guc)
31{
32 struct drm_i915_private *dev_priv = guc_to_i915(guc);
33
34 I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER);
35}
36
37static inline i915_reg_t guc_send_reg(struct intel_guc *guc, u32 i)
38{
39 GEM_BUG_ON(!guc->send_regs.base);
40 GEM_BUG_ON(!guc->send_regs.count);
41 GEM_BUG_ON(i >= guc->send_regs.count);
42
43 return _MMIO(guc->send_regs.base + 4 * i);
44}
45
46void intel_guc_init_send_regs(struct intel_guc *guc)
47{
48 struct drm_i915_private *dev_priv = guc_to_i915(guc);
49 enum forcewake_domains fw_domains = 0;
50 unsigned int i;
51
52 guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0));
53 guc->send_regs.count = SOFT_SCRATCH_COUNT - 1;
54
55 for (i = 0; i < guc->send_regs.count; i++) {
56 fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
57 guc_send_reg(guc, i),
58 FW_REG_READ | FW_REG_WRITE);
59 }
60 guc->send_regs.fw_domains = fw_domains;
61}
62
63void intel_guc_init_early(struct intel_guc *guc)
64{
Michal Wajdeczko0dd940c2017-12-06 13:53:11 +000065 intel_guc_fw_init_early(guc);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000066 intel_guc_ct_init_early(&guc->ct);
Michal Wajdeczko56b9a8b2018-03-14 14:45:39 +000067 intel_guc_log_init_early(&guc->log);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000068
69 mutex_init(&guc->send_mutex);
Michał Winiarskieacd8392018-03-19 10:53:36 +010070 spin_lock_init(&guc->irq_lock);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +000071 guc->send = intel_guc_send_nop;
72 guc->notify = gen8_guc_raise_irq;
73}
74
Michał Winiarski3176ff42017-12-13 23:13:47 +010075int intel_guc_init_wq(struct intel_guc *guc)
76{
77 struct drm_i915_private *dev_priv = guc_to_i915(guc);
78
79 /*
80 * GuC log buffer flush work item has to do register access to
81 * send the ack to GuC and this work item, if not synced before
82 * suspend, can potentially get executed after the GFX device is
83 * suspended.
84 * By marking the WQ as freezable, we don't have to bother about
85 * flushing of this work item from the suspend hooks, the pending
86 * work item if any will be either executed before the suspend
87 * or scheduled later on resume. This way the handling of work
88 * item can be kept same between system suspend & rpm suspend.
89 */
Michał Winiarski6a96be22018-03-19 10:53:42 +010090 guc->log.relay.flush_wq =
91 alloc_ordered_workqueue("i915-guc_log",
92 WQ_HIGHPRI | WQ_FREEZABLE);
93 if (!guc->log.relay.flush_wq) {
Sagar Arun Kamble70deead2018-01-24 21:16:58 +053094 DRM_ERROR("Couldn't allocate workqueue for GuC log\n");
Michał Winiarski3176ff42017-12-13 23:13:47 +010095 return -ENOMEM;
Sagar Arun Kamble70deead2018-01-24 21:16:58 +053096 }
Michał Winiarski3176ff42017-12-13 23:13:47 +010097
98 /*
99 * Even though both sending GuC action, and adding a new workitem to
100 * GuC workqueue are serialized (each with its own locking), since
101 * we're using mutliple engines, it's possible that we're going to
102 * issue a preempt request with two (or more - each for different
103 * engine) workitems in GuC queue. In this situation, GuC may submit
104 * all of them, which will make us very confused.
105 * Our preemption contexts may even already be complete - before we
106 * even had the chance to sent the preempt action to GuC!. Rather
107 * than introducing yet another lock, we can just use ordered workqueue
108 * to make sure we're always sending a single preemption request with a
109 * single workitem.
110 */
111 if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) &&
112 USES_GUC_SUBMISSION(dev_priv)) {
113 guc->preempt_wq = alloc_ordered_workqueue("i915-guc_preempt",
114 WQ_HIGHPRI);
115 if (!guc->preempt_wq) {
Michał Winiarski6a96be22018-03-19 10:53:42 +0100116 destroy_workqueue(guc->log.relay.flush_wq);
Sagar Arun Kamble70deead2018-01-24 21:16:58 +0530117 DRM_ERROR("Couldn't allocate workqueue for GuC "
118 "preemption\n");
Michał Winiarski3176ff42017-12-13 23:13:47 +0100119 return -ENOMEM;
120 }
121 }
122
123 return 0;
124}
125
126void intel_guc_fini_wq(struct intel_guc *guc)
127{
128 struct drm_i915_private *dev_priv = guc_to_i915(guc);
129
130 if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) &&
131 USES_GUC_SUBMISSION(dev_priv))
132 destroy_workqueue(guc->preempt_wq);
133
Michał Winiarski6a96be22018-03-19 10:53:42 +0100134 destroy_workqueue(guc->log.relay.flush_wq);
Michał Winiarski3176ff42017-12-13 23:13:47 +0100135}
136
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100137static int guc_shared_data_create(struct intel_guc *guc)
138{
139 struct i915_vma *vma;
140 void *vaddr;
141
142 vma = intel_guc_allocate_vma(guc, PAGE_SIZE);
143 if (IS_ERR(vma))
144 return PTR_ERR(vma);
145
146 vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB);
147 if (IS_ERR(vaddr)) {
148 i915_vma_unpin_and_release(&vma);
149 return PTR_ERR(vaddr);
150 }
151
152 guc->shared_data = vma;
153 guc->shared_data_vaddr = vaddr;
154
155 return 0;
156}
157
158static void guc_shared_data_destroy(struct intel_guc *guc)
159{
160 i915_gem_object_unpin_map(guc->shared_data->obj);
161 i915_vma_unpin_and_release(&guc->shared_data);
162}
163
164int intel_guc_init(struct intel_guc *guc)
165{
166 struct drm_i915_private *dev_priv = guc_to_i915(guc);
167 int ret;
168
169 ret = guc_shared_data_create(guc);
170 if (ret)
171 return ret;
172 GEM_BUG_ON(!guc->shared_data);
173
Michal Wajdeczko56b9a8b2018-03-14 14:45:39 +0000174 ret = intel_guc_log_create(&guc->log);
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800175 if (ret)
176 goto err_shared;
177
178 ret = intel_guc_ads_create(guc);
179 if (ret)
180 goto err_log;
181 GEM_BUG_ON(!guc->ads_vma);
182
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100183 /* We need to notify the guc whenever we change the GGTT */
184 i915_ggtt_enable_guc(dev_priv);
185
186 return 0;
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800187
188err_log:
Michal Wajdeczko56b9a8b2018-03-14 14:45:39 +0000189 intel_guc_log_destroy(&guc->log);
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800190err_shared:
191 guc_shared_data_destroy(guc);
192 return ret;
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100193}
194
195void intel_guc_fini(struct intel_guc *guc)
196{
197 struct drm_i915_private *dev_priv = guc_to_i915(guc);
198
199 i915_ggtt_disable_guc(dev_priv);
Sujaritha Sundaresanc24f0c12018-01-02 13:20:24 -0800200 intel_guc_ads_destroy(guc);
Michal Wajdeczko56b9a8b2018-03-14 14:45:39 +0000201 intel_guc_log_destroy(&guc->log);
Michał Winiarski1bbbca02017-12-13 23:13:46 +0100202 guc_shared_data_destroy(guc);
203}
204
Michal Wajdeczkofdc6d732017-10-16 14:47:12 +0000205static u32 get_gt_type(struct drm_i915_private *dev_priv)
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000206{
207 /* XXX: GT type based on PCI device ID? field seems unused by fw */
208 return 0;
209}
210
211static u32 get_core_family(struct drm_i915_private *dev_priv)
212{
213 u32 gen = INTEL_GEN(dev_priv);
214
215 switch (gen) {
216 case 9:
217 return GUC_CORE_FAMILY_GEN9;
218
219 default:
220 MISSING_CASE(gen);
221 return GUC_CORE_FAMILY_UNKNOWN;
222 }
223}
224
Michał Winiarskicb5d64e2018-03-19 10:53:45 +0100225static u32 get_log_control_flags(void)
Michal Wajdeczko0ed87952018-01-11 15:24:40 +0000226{
Michał Winiarskicb5d64e2018-03-19 10:53:45 +0100227 u32 level = i915_modparams.guc_log_level;
228 u32 flags = 0;
Michal Wajdeczko0ed87952018-01-11 15:24:40 +0000229
Michał Winiarskicb5d64e2018-03-19 10:53:45 +0100230 GEM_BUG_ON(level < 0);
Michal Wajdeczko0ed87952018-01-11 15:24:40 +0000231
Michał Winiarski03380d12018-03-20 12:55:17 +0100232 if (!GUC_LOG_LEVEL_IS_ENABLED(level))
Michał Winiarskicb5d64e2018-03-19 10:53:45 +0100233 flags |= GUC_LOG_DEFAULT_DISABLED;
234
Michał Winiarski03380d12018-03-20 12:55:17 +0100235 if (!GUC_LOG_LEVEL_IS_VERBOSE(level))
Michał Winiarskicb5d64e2018-03-19 10:53:45 +0100236 flags |= GUC_LOG_DISABLED;
237 else
238 flags |= GUC_LOG_LEVEL_TO_VERBOSITY(level) <<
239 GUC_LOG_VERBOSITY_SHIFT;
240
241 return flags;
Michal Wajdeczko0ed87952018-01-11 15:24:40 +0000242}
243
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000244/*
245 * Initialise the GuC parameter block before starting the firmware
246 * transfer. These parameters are read by the firmware on startup
247 * and cannot be changed thereafter.
248 */
249void intel_guc_init_params(struct intel_guc *guc)
250{
251 struct drm_i915_private *dev_priv = guc_to_i915(guc);
252 u32 params[GUC_CTL_MAX_DWORDS];
253 int i;
254
Michal Wajdeczkofdc6d732017-10-16 14:47:12 +0000255 memset(params, 0, sizeof(params));
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000256
257 params[GUC_CTL_DEVICE_INFO] |=
Michal Wajdeczkofdc6d732017-10-16 14:47:12 +0000258 (get_gt_type(dev_priv) << GUC_CTL_GT_TYPE_SHIFT) |
259 (get_core_family(dev_priv) << GUC_CTL_CORE_FAMILY_SHIFT);
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000260
261 /*
262 * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one
263 * second. This ARAR is calculated by:
264 * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10
265 */
266 params[GUC_CTL_ARAT_HIGH] = 0;
267 params[GUC_CTL_ARAT_LOW] = 100000000;
268
269 params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER;
270
271 params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER |
272 GUC_CTL_VCS2_ENABLED;
273
274 params[GUC_CTL_LOG_PARAMS] = guc->log.flags;
275
Michał Winiarskicb5d64e2018-03-19 10:53:45 +0100276 params[GUC_CTL_DEBUG] = get_log_control_flags();
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000277
278 /* If GuC submission is enabled, set up additional parameters here */
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +0000279 if (USES_GUC_SUBMISSION(dev_priv)) {
Jackie Li3c009e32018-03-13 17:32:49 -0700280 u32 ads = intel_guc_ggtt_offset(guc,
281 guc->ads_vma) >> PAGE_SHIFT;
282 u32 pgs = intel_guc_ggtt_offset(guc, guc->stage_desc_pool);
Michal Wajdeczko5d53be42017-10-16 14:47:11 +0000283 u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16;
284
285 params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
286 params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
287
288 pgs >>= PAGE_SHIFT;
289 params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
290 (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
291
292 params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS;
293
294 /* Unmask this bit to enable the GuC's internal scheduler */
295 params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER;
296 }
297
298 /*
299 * All SOFT_SCRATCH registers are in FORCEWAKE_BLITTER domain and
300 * they are power context saved so it's ok to release forcewake
301 * when we are done here and take it again at xfer time.
302 */
303 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER);
304
305 I915_WRITE(SOFT_SCRATCH(0), 0);
306
307 for (i = 0; i < GUC_CTL_MAX_DWORDS; i++)
308 I915_WRITE(SOFT_SCRATCH(1 + i), params[i]);
309
310 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER);
311}
312
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000313int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len)
314{
315 WARN(1, "Unexpected send: action=%#x\n", *action);
316 return -ENODEV;
317}
318
319/*
320 * This function implements the MMIO based host to GuC interface.
321 */
322int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len)
323{
324 struct drm_i915_private *dev_priv = guc_to_i915(guc);
325 u32 status;
326 int i;
327 int ret;
328
329 GEM_BUG_ON(!len);
330 GEM_BUG_ON(len > guc->send_regs.count);
331
332 /* If CT is available, we expect to use MMIO only during init/fini */
333 GEM_BUG_ON(HAS_GUC_CT(dev_priv) &&
334 *action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER &&
335 *action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER);
336
337 mutex_lock(&guc->send_mutex);
338 intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains);
339
340 for (i = 0; i < len; i++)
341 I915_WRITE(guc_send_reg(guc, i), action[i]);
342
343 POSTING_READ(guc_send_reg(guc, i - 1));
344
345 intel_guc_notify(guc);
346
347 /*
348 * No GuC command should ever take longer than 10ms.
349 * Fast commands should still complete in 10us.
350 */
351 ret = __intel_wait_for_register_fw(dev_priv,
352 guc_send_reg(guc, 0),
353 INTEL_GUC_RECV_MASK,
354 INTEL_GUC_RECV_MASK,
355 10, 10, &status);
356 if (status != INTEL_GUC_STATUS_SUCCESS) {
357 /*
358 * Either the GuC explicitly returned an error (which
359 * we convert to -EIO here) or no response at all was
360 * received within the timeout limit (-ETIMEDOUT)
361 */
362 if (ret != -ETIMEDOUT)
363 ret = -EIO;
364
Michał Winiarskifeb06c12018-03-19 10:53:47 +0100365 DRM_DEBUG_DRIVER("INTEL_GUC_SEND: Action 0x%X failed;"
366 " ret=%d status=0x%08X response=0x%08X\n",
367 action[0], ret, status,
368 I915_READ(SOFT_SCRATCH(15)));
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000369 }
370
371 intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains);
372 mutex_unlock(&guc->send_mutex);
373
374 return ret;
375}
376
Michal Wajdeczko93bf8092018-03-08 16:46:55 +0100377void intel_guc_to_host_event_handler(struct intel_guc *guc)
378{
379 struct drm_i915_private *dev_priv = guc_to_i915(guc);
Michał Winiarskieacd8392018-03-19 10:53:36 +0100380 u32 msg, val;
Michal Wajdeczko93bf8092018-03-08 16:46:55 +0100381
382 /*
383 * Sample the log buffer flush related bits & clear them out now
384 * itself from the message identity register to minimize the
385 * probability of losing a flush interrupt, when there are back
386 * to back flush interrupts.
387 * There can be a new flush interrupt, for different log buffer
388 * type (like for ISR), whilst Host is handling one (for DPC).
389 * Since same bit is used in message register for ISR & DPC, it
390 * could happen that GuC sets the bit for 2nd interrupt but Host
391 * clears out the bit on handling the 1st interrupt.
392 */
Michał Winiarskieacd8392018-03-19 10:53:36 +0100393 spin_lock(&guc->irq_lock);
394 val = I915_READ(SOFT_SCRATCH(15));
395 msg = val & guc->msg_enabled_mask;
396 I915_WRITE(SOFT_SCRATCH(15), val & ~msg);
397 spin_unlock(&guc->irq_lock);
Michal Wajdeczko93bf8092018-03-08 16:46:55 +0100398
Michał Winiarskieacd8392018-03-19 10:53:36 +0100399 if (msg & (INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER |
Michał Winiarski5e24e4a2018-03-19 10:53:44 +0100400 INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED))
Michal Wajdeczkoe9c7e652018-03-19 12:50:49 +0000401 intel_guc_log_handle_flush_event(&guc->log);
Michal Wajdeczko93bf8092018-03-08 16:46:55 +0100402}
403
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000404int intel_guc_sample_forcewake(struct intel_guc *guc)
405{
406 struct drm_i915_private *dev_priv = guc_to_i915(guc);
407 u32 action[2];
408
409 action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE;
Rodrigo Vivid66047e42018-02-22 12:05:35 -0800410 /* WaRsDisableCoarsePowerGating:skl,cnl */
Chris Wilsonfb6db0f2017-12-01 11:30:30 +0000411 if (!HAS_RC6(dev_priv) || NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000412 action[1] = 0;
413 else
414 /* bit 0 and 1 are for Render and Media domain separately */
415 action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA;
416
417 return intel_guc_send(guc, action, ARRAY_SIZE(action));
418}
419
420/**
421 * intel_guc_auth_huc() - Send action to GuC to authenticate HuC ucode
422 * @guc: intel_guc structure
423 * @rsa_offset: rsa offset w.r.t ggtt base of huc vma
424 *
425 * Triggers a HuC firmware authentication request to the GuC via intel_guc_send
426 * INTEL_GUC_ACTION_AUTHENTICATE_HUC interface. This function is invoked by
427 * intel_huc_auth().
428 *
429 * Return: non-zero code on error
430 */
431int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset)
432{
433 u32 action[] = {
434 INTEL_GUC_ACTION_AUTHENTICATE_HUC,
435 rsa_offset
436 };
437
438 return intel_guc_send(guc, action, ARRAY_SIZE(action));
439}
440
441/**
442 * intel_guc_suspend() - notify GuC entering suspend state
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000443 * @guc: the guc
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000444 */
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000445int intel_guc_suspend(struct intel_guc *guc)
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000446{
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000447 u32 data[] = {
448 INTEL_GUC_ACTION_ENTER_S_STATE,
449 GUC_POWER_D1, /* any value greater than GUC_POWER_D0 */
Jackie Li3c009e32018-03-13 17:32:49 -0700450 intel_guc_ggtt_offset(guc, guc->shared_data)
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000451 };
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000452
453 return intel_guc_send(guc, data, ARRAY_SIZE(data));
454}
455
456/**
Michel Thierry6acbea82017-10-31 15:53:09 -0700457 * intel_guc_reset_engine() - ask GuC to reset an engine
458 * @guc: intel_guc structure
459 * @engine: engine to be reset
460 */
461int intel_guc_reset_engine(struct intel_guc *guc,
462 struct intel_engine_cs *engine)
463{
464 u32 data[7];
465
466 GEM_BUG_ON(!guc->execbuf_client);
467
468 data[0] = INTEL_GUC_ACTION_REQUEST_ENGINE_RESET;
469 data[1] = engine->guc_id;
470 data[2] = 0;
471 data[3] = 0;
472 data[4] = 0;
473 data[5] = guc->execbuf_client->stage_id;
Jackie Li3c009e32018-03-13 17:32:49 -0700474 data[6] = intel_guc_ggtt_offset(guc, guc->shared_data);
Michel Thierry6acbea82017-10-31 15:53:09 -0700475
476 return intel_guc_send(guc, data, ARRAY_SIZE(data));
477}
478
479/**
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000480 * intel_guc_resume() - notify GuC resuming from suspend state
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000481 * @guc: the guc
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000482 */
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000483int intel_guc_resume(struct intel_guc *guc)
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000484{
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000485 u32 data[] = {
486 INTEL_GUC_ACTION_EXIT_S_STATE,
487 GUC_POWER_D0,
Jackie Li3c009e32018-03-13 17:32:49 -0700488 intel_guc_ggtt_offset(guc, guc->shared_data)
Michal Wajdeczko7cfca4a2018-03-02 11:15:49 +0000489 };
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000490
491 return intel_guc_send(guc, data, ARRAY_SIZE(data));
492}
493
494/**
Jackie Li6b0478f2018-03-13 17:32:50 -0700495 * DOC: GuC Address Space
496 *
497 * The layout of GuC address space is shown as below:
498 *
499 * +==============> +====================+ <== GUC_GGTT_TOP
500 * ^ | |
501 * | | |
502 * | | DRAM |
503 * | | Memory |
504 * | | |
505 * GuC | |
506 * Address +========> +====================+ <== WOPCM Top
507 * Space ^ | HW contexts RSVD |
508 * | | | WOPCM |
509 * | | +==> +--------------------+ <== GuC WOPCM Top
510 * | GuC ^ | |
511 * | GGTT | | |
512 * | Pin GuC | GuC |
513 * | Bias WOPCM | WOPCM |
514 * | | Size | |
515 * | | | | |
516 * v v v | |
517 * +=====+=====+==> +====================+ <== GuC WOPCM Base
518 * | Non-GuC WOPCM |
519 * | (HuC/Reserved) |
520 * +====================+ <== WOPCM Base
521 *
522 * The lower part [0, GuC ggtt_pin_bias) is mapped to WOPCM which consists of
523 * GuC WOPCM and WOPCM reserved for other usage (e.g.RC6 context). The value of
524 * the GuC ggtt_pin_bias is determined by the actually GuC WOPCM size which is
525 * set in GUC_WOPCM_SIZE register.
526 */
527
528/**
529 * intel_guc_init_ggtt_pin_bias() - Initialize the GuC ggtt_pin_bias value.
530 * @guc: intel_guc structure.
531 *
532 * This function will calculate and initialize the ggtt_pin_bias value based on
533 * overall WOPCM size and GuC WOPCM size.
534 */
535void intel_guc_init_ggtt_pin_bias(struct intel_guc *guc)
536{
537 struct drm_i915_private *i915 = guc_to_i915(guc);
538
539 GEM_BUG_ON(!i915->wopcm.size);
540 GEM_BUG_ON(i915->wopcm.size < i915->wopcm.guc.base);
541
542 guc->ggtt_pin_bias = i915->wopcm.size - i915->wopcm.guc.base;
543}
544
545/**
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000546 * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage
547 * @guc: the guc
548 * @size: size of area to allocate (both virtual space and memory)
549 *
550 * This is a wrapper to create an object for use with the GuC. In order to
551 * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
552 * both some backing storage and a range inside the Global GTT. We must pin
Jackie Li6b0478f2018-03-13 17:32:50 -0700553 * it in the GGTT somewhere other than than [0, GUC ggtt_pin_bias) because that
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000554 * range is reserved inside GuC.
555 *
556 * Return: A i915_vma if successful, otherwise an ERR_PTR.
557 */
558struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
559{
560 struct drm_i915_private *dev_priv = guc_to_i915(guc);
561 struct drm_i915_gem_object *obj;
562 struct i915_vma *vma;
563 int ret;
564
565 obj = i915_gem_object_create(dev_priv, size);
566 if (IS_ERR(obj))
567 return ERR_CAST(obj);
568
569 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
570 if (IS_ERR(vma))
571 goto err;
572
573 ret = i915_vma_pin(vma, 0, PAGE_SIZE,
Jackie Li6b0478f2018-03-13 17:32:50 -0700574 PIN_GLOBAL | PIN_OFFSET_BIAS | guc->ggtt_pin_bias);
Michal Wajdeczko9bf384c2017-10-04 18:13:41 +0000575 if (ret) {
576 vma = ERR_PTR(ret);
577 goto err;
578 }
579
580 return vma;
581
582err:
583 i915_gem_object_put(obj);
584 return vma;
585}