intel_guc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /*
  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. #include "intel_guc.h"
  25. #include "intel_guc_ads.h"
  26. #include "intel_guc_submission.h"
  27. #include "i915_drv.h"
  28. static void gen8_guc_raise_irq(struct intel_guc *guc)
  29. {
  30. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  31. I915_WRITE(GUC_SEND_INTERRUPT, GUC_SEND_TRIGGER);
  32. }
  33. static inline i915_reg_t guc_send_reg(struct intel_guc *guc, u32 i)
  34. {
  35. GEM_BUG_ON(!guc->send_regs.base);
  36. GEM_BUG_ON(!guc->send_regs.count);
  37. GEM_BUG_ON(i >= guc->send_regs.count);
  38. return _MMIO(guc->send_regs.base + 4 * i);
  39. }
  40. void intel_guc_init_send_regs(struct intel_guc *guc)
  41. {
  42. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  43. enum forcewake_domains fw_domains = 0;
  44. unsigned int i;
  45. guc->send_regs.base = i915_mmio_reg_offset(SOFT_SCRATCH(0));
  46. guc->send_regs.count = SOFT_SCRATCH_COUNT - 1;
  47. for (i = 0; i < guc->send_regs.count; i++) {
  48. fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
  49. guc_send_reg(guc, i),
  50. FW_REG_READ | FW_REG_WRITE);
  51. }
  52. guc->send_regs.fw_domains = fw_domains;
  53. }
  54. void intel_guc_init_early(struct intel_guc *guc)
  55. {
  56. intel_guc_fw_init_early(guc);
  57. intel_guc_ct_init_early(&guc->ct);
  58. intel_guc_log_init_early(&guc->log);
  59. mutex_init(&guc->send_mutex);
  60. spin_lock_init(&guc->irq_lock);
  61. guc->send = intel_guc_send_nop;
  62. guc->handler = intel_guc_to_host_event_handler_nop;
  63. guc->notify = gen8_guc_raise_irq;
  64. }
  65. int intel_guc_init_wq(struct intel_guc *guc)
  66. {
  67. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  68. /*
  69. * GuC log buffer flush work item has to do register access to
  70. * send the ack to GuC and this work item, if not synced before
  71. * suspend, can potentially get executed after the GFX device is
  72. * suspended.
  73. * By marking the WQ as freezable, we don't have to bother about
  74. * flushing of this work item from the suspend hooks, the pending
  75. * work item if any will be either executed before the suspend
  76. * or scheduled later on resume. This way the handling of work
  77. * item can be kept same between system suspend & rpm suspend.
  78. */
  79. guc->log.relay.flush_wq =
  80. alloc_ordered_workqueue("i915-guc_log",
  81. WQ_HIGHPRI | WQ_FREEZABLE);
  82. if (!guc->log.relay.flush_wq) {
  83. DRM_ERROR("Couldn't allocate workqueue for GuC log\n");
  84. return -ENOMEM;
  85. }
  86. /*
  87. * Even though both sending GuC action, and adding a new workitem to
  88. * GuC workqueue are serialized (each with its own locking), since
  89. * we're using mutliple engines, it's possible that we're going to
  90. * issue a preempt request with two (or more - each for different
  91. * engine) workitems in GuC queue. In this situation, GuC may submit
  92. * all of them, which will make us very confused.
  93. * Our preemption contexts may even already be complete - before we
  94. * even had the chance to sent the preempt action to GuC!. Rather
  95. * than introducing yet another lock, we can just use ordered workqueue
  96. * to make sure we're always sending a single preemption request with a
  97. * single workitem.
  98. */
  99. if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) &&
  100. USES_GUC_SUBMISSION(dev_priv)) {
  101. guc->preempt_wq = alloc_ordered_workqueue("i915-guc_preempt",
  102. WQ_HIGHPRI);
  103. if (!guc->preempt_wq) {
  104. destroy_workqueue(guc->log.relay.flush_wq);
  105. DRM_ERROR("Couldn't allocate workqueue for GuC "
  106. "preemption\n");
  107. return -ENOMEM;
  108. }
  109. }
  110. return 0;
  111. }
  112. void intel_guc_fini_wq(struct intel_guc *guc)
  113. {
  114. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  115. if (HAS_LOGICAL_RING_PREEMPTION(dev_priv) &&
  116. USES_GUC_SUBMISSION(dev_priv))
  117. destroy_workqueue(guc->preempt_wq);
  118. destroy_workqueue(guc->log.relay.flush_wq);
  119. }
  120. static int guc_shared_data_create(struct intel_guc *guc)
  121. {
  122. struct i915_vma *vma;
  123. void *vaddr;
  124. vma = intel_guc_allocate_vma(guc, PAGE_SIZE);
  125. if (IS_ERR(vma))
  126. return PTR_ERR(vma);
  127. vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB);
  128. if (IS_ERR(vaddr)) {
  129. i915_vma_unpin_and_release(&vma);
  130. return PTR_ERR(vaddr);
  131. }
  132. guc->shared_data = vma;
  133. guc->shared_data_vaddr = vaddr;
  134. return 0;
  135. }
  136. static void guc_shared_data_destroy(struct intel_guc *guc)
  137. {
  138. i915_gem_object_unpin_map(guc->shared_data->obj);
  139. i915_vma_unpin_and_release(&guc->shared_data);
  140. }
  141. int intel_guc_init(struct intel_guc *guc)
  142. {
  143. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  144. int ret;
  145. ret = guc_shared_data_create(guc);
  146. if (ret)
  147. return ret;
  148. GEM_BUG_ON(!guc->shared_data);
  149. ret = intel_guc_log_create(&guc->log);
  150. if (ret)
  151. goto err_shared;
  152. ret = intel_guc_ads_create(guc);
  153. if (ret)
  154. goto err_log;
  155. GEM_BUG_ON(!guc->ads_vma);
  156. /* We need to notify the guc whenever we change the GGTT */
  157. i915_ggtt_enable_guc(dev_priv);
  158. return 0;
  159. err_log:
  160. intel_guc_log_destroy(&guc->log);
  161. err_shared:
  162. guc_shared_data_destroy(guc);
  163. return ret;
  164. }
  165. void intel_guc_fini(struct intel_guc *guc)
  166. {
  167. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  168. i915_ggtt_disable_guc(dev_priv);
  169. intel_guc_ads_destroy(guc);
  170. intel_guc_log_destroy(&guc->log);
  171. guc_shared_data_destroy(guc);
  172. }
  173. static u32 get_log_control_flags(void)
  174. {
  175. u32 level = i915_modparams.guc_log_level;
  176. u32 flags = 0;
  177. GEM_BUG_ON(level < 0);
  178. if (!GUC_LOG_LEVEL_IS_ENABLED(level))
  179. flags |= GUC_LOG_DEFAULT_DISABLED;
  180. if (!GUC_LOG_LEVEL_IS_VERBOSE(level))
  181. flags |= GUC_LOG_DISABLED;
  182. else
  183. flags |= GUC_LOG_LEVEL_TO_VERBOSITY(level) <<
  184. GUC_LOG_VERBOSITY_SHIFT;
  185. return flags;
  186. }
  187. /*
  188. * Initialise the GuC parameter block before starting the firmware
  189. * transfer. These parameters are read by the firmware on startup
  190. * and cannot be changed thereafter.
  191. */
  192. void intel_guc_init_params(struct intel_guc *guc)
  193. {
  194. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  195. u32 params[GUC_CTL_MAX_DWORDS];
  196. int i;
  197. memset(params, 0, sizeof(params));
  198. /*
  199. * GuC ARAT increment is 10 ns. GuC default scheduler quantum is one
  200. * second. This ARAR is calculated by:
  201. * Scheduler-Quantum-in-ns / ARAT-increment-in-ns = 1000000000 / 10
  202. */
  203. params[GUC_CTL_ARAT_HIGH] = 0;
  204. params[GUC_CTL_ARAT_LOW] = 100000000;
  205. params[GUC_CTL_WA] |= GUC_CTL_WA_UK_BY_DRIVER;
  206. params[GUC_CTL_FEATURE] |= GUC_CTL_DISABLE_SCHEDULER |
  207. GUC_CTL_VCS2_ENABLED;
  208. params[GUC_CTL_LOG_PARAMS] = guc->log.flags;
  209. params[GUC_CTL_DEBUG] = get_log_control_flags();
  210. /* If GuC submission is enabled, set up additional parameters here */
  211. if (USES_GUC_SUBMISSION(dev_priv)) {
  212. u32 ads = intel_guc_ggtt_offset(guc,
  213. guc->ads_vma) >> PAGE_SHIFT;
  214. u32 pgs = intel_guc_ggtt_offset(guc, guc->stage_desc_pool);
  215. u32 ctx_in_16 = GUC_MAX_STAGE_DESCRIPTORS / 16;
  216. params[GUC_CTL_DEBUG] |= ads << GUC_ADS_ADDR_SHIFT;
  217. params[GUC_CTL_DEBUG] |= GUC_ADS_ENABLED;
  218. pgs >>= PAGE_SHIFT;
  219. params[GUC_CTL_CTXINFO] = (pgs << GUC_CTL_BASE_ADDR_SHIFT) |
  220. (ctx_in_16 << GUC_CTL_CTXNUM_IN16_SHIFT);
  221. params[GUC_CTL_FEATURE] |= GUC_CTL_KERNEL_SUBMISSIONS;
  222. /* Unmask this bit to enable the GuC's internal scheduler */
  223. params[GUC_CTL_FEATURE] &= ~GUC_CTL_DISABLE_SCHEDULER;
  224. }
  225. /*
  226. * All SOFT_SCRATCH registers are in FORCEWAKE_BLITTER domain and
  227. * they are power context saved so it's ok to release forcewake
  228. * when we are done here and take it again at xfer time.
  229. */
  230. intel_uncore_forcewake_get(dev_priv, FORCEWAKE_BLITTER);
  231. I915_WRITE(SOFT_SCRATCH(0), 0);
  232. for (i = 0; i < GUC_CTL_MAX_DWORDS; i++)
  233. I915_WRITE(SOFT_SCRATCH(1 + i), params[i]);
  234. intel_uncore_forcewake_put(dev_priv, FORCEWAKE_BLITTER);
  235. }
  236. int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len,
  237. u32 *response_buf, u32 response_buf_size)
  238. {
  239. WARN(1, "Unexpected send: action=%#x\n", *action);
  240. return -ENODEV;
  241. }
  242. void intel_guc_to_host_event_handler_nop(struct intel_guc *guc)
  243. {
  244. WARN(1, "Unexpected event: no suitable handler\n");
  245. }
  246. /*
  247. * This function implements the MMIO based host to GuC interface.
  248. */
  249. int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
  250. u32 *response_buf, u32 response_buf_size)
  251. {
  252. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  253. u32 status;
  254. int i;
  255. int ret;
  256. GEM_BUG_ON(!len);
  257. GEM_BUG_ON(len > guc->send_regs.count);
  258. /* We expect only action code */
  259. GEM_BUG_ON(*action & ~INTEL_GUC_MSG_CODE_MASK);
  260. /* If CT is available, we expect to use MMIO only during init/fini */
  261. GEM_BUG_ON(HAS_GUC_CT(dev_priv) &&
  262. *action != INTEL_GUC_ACTION_REGISTER_COMMAND_TRANSPORT_BUFFER &&
  263. *action != INTEL_GUC_ACTION_DEREGISTER_COMMAND_TRANSPORT_BUFFER);
  264. mutex_lock(&guc->send_mutex);
  265. intel_uncore_forcewake_get(dev_priv, guc->send_regs.fw_domains);
  266. for (i = 0; i < len; i++)
  267. I915_WRITE(guc_send_reg(guc, i), action[i]);
  268. POSTING_READ(guc_send_reg(guc, i - 1));
  269. intel_guc_notify(guc);
  270. /*
  271. * No GuC command should ever take longer than 10ms.
  272. * Fast commands should still complete in 10us.
  273. */
  274. ret = __intel_wait_for_register_fw(dev_priv,
  275. guc_send_reg(guc, 0),
  276. INTEL_GUC_MSG_TYPE_MASK,
  277. INTEL_GUC_MSG_TYPE_RESPONSE <<
  278. INTEL_GUC_MSG_TYPE_SHIFT,
  279. 10, 10, &status);
  280. /* If GuC explicitly returned an error, convert it to -EIO */
  281. if (!ret && !INTEL_GUC_MSG_IS_RESPONSE_SUCCESS(status))
  282. ret = -EIO;
  283. if (ret) {
  284. DRM_DEBUG_DRIVER("INTEL_GUC_SEND: Action 0x%X failed;"
  285. " ret=%d status=0x%08X response=0x%08X\n",
  286. action[0], ret, status,
  287. I915_READ(SOFT_SCRATCH(15)));
  288. goto out;
  289. }
  290. if (response_buf) {
  291. int count = min(response_buf_size, guc->send_regs.count - 1);
  292. for (i = 0; i < count; i++)
  293. response_buf[i] = I915_READ(guc_send_reg(guc, i + 1));
  294. }
  295. /* Use data from the GuC response as our return value */
  296. ret = INTEL_GUC_MSG_TO_DATA(status);
  297. out:
  298. intel_uncore_forcewake_put(dev_priv, guc->send_regs.fw_domains);
  299. mutex_unlock(&guc->send_mutex);
  300. return ret;
  301. }
  302. void intel_guc_to_host_event_handler_mmio(struct intel_guc *guc)
  303. {
  304. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  305. u32 msg, val;
  306. /*
  307. * Sample the log buffer flush related bits & clear them out now
  308. * itself from the message identity register to minimize the
  309. * probability of losing a flush interrupt, when there are back
  310. * to back flush interrupts.
  311. * There can be a new flush interrupt, for different log buffer
  312. * type (like for ISR), whilst Host is handling one (for DPC).
  313. * Since same bit is used in message register for ISR & DPC, it
  314. * could happen that GuC sets the bit for 2nd interrupt but Host
  315. * clears out the bit on handling the 1st interrupt.
  316. */
  317. spin_lock(&guc->irq_lock);
  318. val = I915_READ(SOFT_SCRATCH(15));
  319. msg = val & guc->msg_enabled_mask;
  320. I915_WRITE(SOFT_SCRATCH(15), val & ~msg);
  321. spin_unlock(&guc->irq_lock);
  322. intel_guc_to_host_process_recv_msg(guc, msg);
  323. }
  324. void intel_guc_to_host_process_recv_msg(struct intel_guc *guc, u32 msg)
  325. {
  326. /* Make sure to handle only enabled messages */
  327. msg &= guc->msg_enabled_mask;
  328. if (msg & (INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER |
  329. INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED))
  330. intel_guc_log_handle_flush_event(&guc->log);
  331. }
  332. int intel_guc_sample_forcewake(struct intel_guc *guc)
  333. {
  334. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  335. u32 action[2];
  336. action[0] = INTEL_GUC_ACTION_SAMPLE_FORCEWAKE;
  337. /* WaRsDisableCoarsePowerGating:skl,cnl */
  338. if (!HAS_RC6(dev_priv) || NEEDS_WaRsDisableCoarsePowerGating(dev_priv))
  339. action[1] = 0;
  340. else
  341. /* bit 0 and 1 are for Render and Media domain separately */
  342. action[1] = GUC_FORCEWAKE_RENDER | GUC_FORCEWAKE_MEDIA;
  343. return intel_guc_send(guc, action, ARRAY_SIZE(action));
  344. }
  345. /**
  346. * intel_guc_auth_huc() - Send action to GuC to authenticate HuC ucode
  347. * @guc: intel_guc structure
  348. * @rsa_offset: rsa offset w.r.t ggtt base of huc vma
  349. *
  350. * Triggers a HuC firmware authentication request to the GuC via intel_guc_send
  351. * INTEL_GUC_ACTION_AUTHENTICATE_HUC interface. This function is invoked by
  352. * intel_huc_auth().
  353. *
  354. * Return: non-zero code on error
  355. */
  356. int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset)
  357. {
  358. u32 action[] = {
  359. INTEL_GUC_ACTION_AUTHENTICATE_HUC,
  360. rsa_offset
  361. };
  362. return intel_guc_send(guc, action, ARRAY_SIZE(action));
  363. }
  364. /**
  365. * intel_guc_suspend() - notify GuC entering suspend state
  366. * @guc: the guc
  367. */
  368. int intel_guc_suspend(struct intel_guc *guc)
  369. {
  370. u32 data[] = {
  371. INTEL_GUC_ACTION_ENTER_S_STATE,
  372. GUC_POWER_D1, /* any value greater than GUC_POWER_D0 */
  373. intel_guc_ggtt_offset(guc, guc->shared_data)
  374. };
  375. return intel_guc_send(guc, data, ARRAY_SIZE(data));
  376. }
  377. /**
  378. * intel_guc_reset_engine() - ask GuC to reset an engine
  379. * @guc: intel_guc structure
  380. * @engine: engine to be reset
  381. */
  382. int intel_guc_reset_engine(struct intel_guc *guc,
  383. struct intel_engine_cs *engine)
  384. {
  385. u32 data[7];
  386. GEM_BUG_ON(!guc->execbuf_client);
  387. data[0] = INTEL_GUC_ACTION_REQUEST_ENGINE_RESET;
  388. data[1] = engine->guc_id;
  389. data[2] = 0;
  390. data[3] = 0;
  391. data[4] = 0;
  392. data[5] = guc->execbuf_client->stage_id;
  393. data[6] = intel_guc_ggtt_offset(guc, guc->shared_data);
  394. return intel_guc_send(guc, data, ARRAY_SIZE(data));
  395. }
  396. /**
  397. * intel_guc_resume() - notify GuC resuming from suspend state
  398. * @guc: the guc
  399. */
  400. int intel_guc_resume(struct intel_guc *guc)
  401. {
  402. u32 data[] = {
  403. INTEL_GUC_ACTION_EXIT_S_STATE,
  404. GUC_POWER_D0,
  405. intel_guc_ggtt_offset(guc, guc->shared_data)
  406. };
  407. return intel_guc_send(guc, data, ARRAY_SIZE(data));
  408. }
  409. /**
  410. * DOC: GuC Address Space
  411. *
  412. * The layout of GuC address space is shown below:
  413. *
  414. * ::
  415. *
  416. * +==============> +====================+ <== GUC_GGTT_TOP
  417. * ^ | |
  418. * | | |
  419. * | | DRAM |
  420. * | | Memory |
  421. * | | |
  422. * GuC | |
  423. * Address +========> +====================+ <== WOPCM Top
  424. * Space ^ | HW contexts RSVD |
  425. * | | | WOPCM |
  426. * | | +==> +--------------------+ <== GuC WOPCM Top
  427. * | GuC ^ | |
  428. * | GGTT | | |
  429. * | Pin GuC | GuC |
  430. * | Bias WOPCM | WOPCM |
  431. * | | Size | |
  432. * | | | | |
  433. * v v v | |
  434. * +=====+=====+==> +====================+ <== GuC WOPCM Base
  435. * | Non-GuC WOPCM |
  436. * | (HuC/Reserved) |
  437. * +====================+ <== WOPCM Base
  438. *
  439. * The lower part of GuC Address Space [0, ggtt_pin_bias) is mapped to WOPCM
  440. * while upper part of GuC Address Space [ggtt_pin_bias, GUC_GGTT_TOP) is mapped
  441. * to DRAM. The value of the GuC ggtt_pin_bias is determined by WOPCM size and
  442. * actual GuC WOPCM size.
  443. */
  444. /**
  445. * intel_guc_init_ggtt_pin_bias() - Initialize the GuC ggtt_pin_bias value.
  446. * @guc: intel_guc structure.
  447. *
  448. * This function will calculate and initialize the ggtt_pin_bias value based on
  449. * overall WOPCM size and GuC WOPCM size.
  450. */
  451. void intel_guc_init_ggtt_pin_bias(struct intel_guc *guc)
  452. {
  453. struct drm_i915_private *i915 = guc_to_i915(guc);
  454. GEM_BUG_ON(!i915->wopcm.size);
  455. GEM_BUG_ON(i915->wopcm.size < i915->wopcm.guc.base);
  456. guc->ggtt_pin_bias = i915->wopcm.size - i915->wopcm.guc.base;
  457. }
  458. /**
  459. * intel_guc_allocate_vma() - Allocate a GGTT VMA for GuC usage
  460. * @guc: the guc
  461. * @size: size of area to allocate (both virtual space and memory)
  462. *
  463. * This is a wrapper to create an object for use with the GuC. In order to
  464. * use it inside the GuC, an object needs to be pinned lifetime, so we allocate
  465. * both some backing storage and a range inside the Global GTT. We must pin
  466. * it in the GGTT somewhere other than than [0, GUC ggtt_pin_bias) because that
  467. * range is reserved inside GuC.
  468. *
  469. * Return: A i915_vma if successful, otherwise an ERR_PTR.
  470. */
  471. struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size)
  472. {
  473. struct drm_i915_private *dev_priv = guc_to_i915(guc);
  474. struct drm_i915_gem_object *obj;
  475. struct i915_vma *vma;
  476. int ret;
  477. obj = i915_gem_object_create(dev_priv, size);
  478. if (IS_ERR(obj))
  479. return ERR_CAST(obj);
  480. vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
  481. if (IS_ERR(vma))
  482. goto err;
  483. ret = i915_vma_pin(vma, 0, PAGE_SIZE,
  484. PIN_GLOBAL | PIN_OFFSET_BIAS | guc->ggtt_pin_bias);
  485. if (ret) {
  486. vma = ERR_PTR(ret);
  487. goto err;
  488. }
  489. return vma;
  490. err:
  491. i915_gem_object_put(obj);
  492. return vma;
  493. }