intel_guc.h 6.0 KB

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