intel_guc.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #ifndef _INTEL_GUC_H_
  25. #define _INTEL_GUC_H_
  26. #include "intel_uncore.h"
  27. #include "intel_guc_fw.h"
  28. #include "intel_guc_fwif.h"
  29. #include "intel_guc_ct.h"
  30. #include "intel_guc_log.h"
  31. #include "intel_guc_reg.h"
  32. #include "intel_uc_fw.h"
  33. #include "i915_vma.h"
  34. struct guc_preempt_work {
  35. struct work_struct work;
  36. struct intel_engine_cs *engine;
  37. };
  38. /*
  39. * Top level structure of GuC. It handles firmware loading and manages client
  40. * pool and doorbells. intel_guc owns a intel_guc_client to replace the legacy
  41. * ExecList submission.
  42. */
  43. struct intel_guc {
  44. struct intel_uc_fw fw;
  45. struct intel_guc_log log;
  46. struct intel_guc_ct ct;
  47. /* Offset where Non-WOPCM memory starts. */
  48. u32 ggtt_pin_bias;
  49. /* Log snapshot if GuC errors during load */
  50. struct drm_i915_gem_object *load_err_log;
  51. /* intel_guc_recv interrupt related state */
  52. spinlock_t irq_lock;
  53. bool interrupts_enabled;
  54. unsigned int msg_enabled_mask;
  55. struct i915_vma *ads_vma;
  56. struct i915_vma *stage_desc_pool;
  57. void *stage_desc_pool_vaddr;
  58. struct ida stage_ids;
  59. struct i915_vma *shared_data;
  60. void *shared_data_vaddr;
  61. struct intel_guc_client *execbuf_client;
  62. struct intel_guc_client *preempt_client;
  63. struct guc_preempt_work preempt_work[I915_NUM_ENGINES];
  64. struct workqueue_struct *preempt_wq;
  65. DECLARE_BITMAP(doorbell_bitmap, GUC_NUM_DOORBELLS);
  66. /* Cyclic counter mod pagesize */
  67. u32 db_cacheline;
  68. /* GuC's FW specific registers used in MMIO send */
  69. struct {
  70. u32 base;
  71. unsigned int count;
  72. enum forcewake_domains fw_domains;
  73. } send_regs;
  74. /* To serialize the intel_guc_send actions */
  75. struct mutex send_mutex;
  76. /* GuC's FW specific send function */
  77. int (*send)(struct intel_guc *guc, const u32 *data, u32 len,
  78. u32 *response_buf, u32 response_buf_size);
  79. /* GuC's FW specific event handler function */
  80. void (*handler)(struct intel_guc *guc);
  81. /* GuC's FW specific notify function */
  82. void (*notify)(struct intel_guc *guc);
  83. };
  84. static
  85. inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len)
  86. {
  87. return guc->send(guc, action, len, NULL, 0);
  88. }
  89. static inline int
  90. intel_guc_send_and_receive(struct intel_guc *guc, const u32 *action, u32 len,
  91. u32 *response_buf, u32 response_buf_size)
  92. {
  93. return guc->send(guc, action, len, response_buf, response_buf_size);
  94. }
  95. static inline void intel_guc_notify(struct intel_guc *guc)
  96. {
  97. guc->notify(guc);
  98. }
  99. static inline void intel_guc_to_host_event_handler(struct intel_guc *guc)
  100. {
  101. guc->handler(guc);
  102. }
  103. /* GuC addresses above GUC_GGTT_TOP also don't map through the GTT */
  104. #define GUC_GGTT_TOP 0xFEE00000
  105. /**
  106. * intel_guc_ggtt_offset() - Get and validate the GGTT offset of @vma
  107. * @guc: intel_guc structure.
  108. * @vma: i915 graphics virtual memory area.
  109. *
  110. * GuC does not allow any gfx GGTT address that falls into range
  111. * [0, GuC ggtt_pin_bias), which is reserved for Boot ROM, SRAM and WOPCM.
  112. * Currently, in order to exclude [0, GuC ggtt_pin_bias) address space from
  113. * GGTT, all gfx objects used by GuC are allocated with intel_guc_allocate_vma()
  114. * and pinned with PIN_OFFSET_BIAS along with the value of GuC ggtt_pin_bias.
  115. *
  116. * Return: GGTT offset of the @vma.
  117. */
  118. static inline u32 intel_guc_ggtt_offset(struct intel_guc *guc,
  119. struct i915_vma *vma)
  120. {
  121. u32 offset = i915_ggtt_offset(vma);
  122. GEM_BUG_ON(offset < guc->ggtt_pin_bias);
  123. GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
  124. return offset;
  125. }
  126. void intel_guc_init_early(struct intel_guc *guc);
  127. void intel_guc_init_send_regs(struct intel_guc *guc);
  128. void intel_guc_init_params(struct intel_guc *guc);
  129. void intel_guc_init_ggtt_pin_bias(struct intel_guc *guc);
  130. int intel_guc_init_wq(struct intel_guc *guc);
  131. void intel_guc_fini_wq(struct intel_guc *guc);
  132. int intel_guc_init(struct intel_guc *guc);
  133. void intel_guc_fini(struct intel_guc *guc);
  134. int intel_guc_send_nop(struct intel_guc *guc, const u32 *action, u32 len,
  135. u32 *response_buf, u32 response_buf_size);
  136. int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len,
  137. u32 *response_buf, u32 response_buf_size);
  138. void intel_guc_to_host_event_handler(struct intel_guc *guc);
  139. void intel_guc_to_host_event_handler_nop(struct intel_guc *guc);
  140. void intel_guc_to_host_event_handler_mmio(struct intel_guc *guc);
  141. void intel_guc_to_host_process_recv_msg(struct intel_guc *guc, u32 msg);
  142. int intel_guc_sample_forcewake(struct intel_guc *guc);
  143. int intel_guc_auth_huc(struct intel_guc *guc, u32 rsa_offset);
  144. int intel_guc_suspend(struct intel_guc *guc);
  145. int intel_guc_resume(struct intel_guc *guc);
  146. struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
  147. static inline int intel_guc_sanitize(struct intel_guc *guc)
  148. {
  149. intel_uc_fw_sanitize(&guc->fw);
  150. return 0;
  151. }
  152. static inline void intel_guc_enable_msg(struct intel_guc *guc, u32 mask)
  153. {
  154. spin_lock_irq(&guc->irq_lock);
  155. guc->msg_enabled_mask |= mask;
  156. spin_unlock_irq(&guc->irq_lock);
  157. }
  158. static inline void intel_guc_disable_msg(struct intel_guc *guc, u32 mask)
  159. {
  160. spin_lock_irq(&guc->irq_lock);
  161. guc->msg_enabled_mask &= ~mask;
  162. spin_unlock_irq(&guc->irq_lock);
  163. }
  164. #endif