intel_uc.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright © 2014 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_UC_H_
  25. #define _INTEL_UC_H_
  26. #include "intel_guc_fwif.h"
  27. #include "i915_guc_reg.h"
  28. #include "intel_ringbuffer.h"
  29. #include "i915_vma.h"
  30. struct drm_i915_gem_request;
  31. /*
  32. * This structure primarily describes the GEM object shared with the GuC.
  33. * The GEM object is held for the entire lifetime of our interaction with
  34. * the GuC, being allocated before the GuC is loaded with its firmware.
  35. * Because there's no way to update the address used by the GuC after
  36. * initialisation, the shared object must stay pinned into the GGTT as
  37. * long as the GuC is in use. We also keep the first page (only) mapped
  38. * into kernel address space, as it includes shared data that must be
  39. * updated on every request submission.
  40. *
  41. * The single GEM object described here is actually made up of several
  42. * separate areas, as far as the GuC is concerned. The first page (kept
  43. * kmap'd) includes the "process decriptor" which holds sequence data for
  44. * the doorbell, and one cacheline which actually *is* the doorbell; a
  45. * write to this will "ring the doorbell" (i.e. send an interrupt to the
  46. * GuC). The subsequent pages of the client object constitute the work
  47. * queue (a circular array of work items), again described in the process
  48. * descriptor. Work queue pages are mapped momentarily as required.
  49. *
  50. * We also keep a few statistics on failures. Ideally, these should all
  51. * be zero!
  52. * no_wq_space: times that the submission pre-check found no space was
  53. * available in the work queue (note, the queue is shared,
  54. * not per-engine). It is OK for this to be nonzero, but
  55. * it should not be huge!
  56. * q_fail: failed to enqueue a work item. This should never happen,
  57. * because we check for space beforehand.
  58. * b_fail: failed to ring the doorbell. This should never happen, unless
  59. * somehow the hardware misbehaves, or maybe if the GuC firmware
  60. * crashes? We probably need to reset the GPU to recover.
  61. * retcode: errno from last guc_submit()
  62. */
  63. struct i915_guc_client {
  64. struct i915_vma *vma;
  65. void *vaddr;
  66. struct i915_gem_context *owner;
  67. struct intel_guc *guc;
  68. uint32_t engines; /* bitmap of (host) engine ids */
  69. uint32_t priority;
  70. uint32_t ctx_index;
  71. uint32_t proc_desc_offset;
  72. uint32_t doorbell_offset;
  73. uint32_t doorbell_cookie;
  74. uint16_t doorbell_id;
  75. uint16_t padding[3]; /* Maintain alignment */
  76. spinlock_t wq_lock;
  77. uint32_t wq_offset;
  78. uint32_t wq_size;
  79. uint32_t wq_tail;
  80. uint32_t wq_rsvd;
  81. uint32_t no_wq_space;
  82. uint32_t b_fail;
  83. int retcode;
  84. /* Per-engine counts of GuC submissions */
  85. uint64_t submissions[I915_NUM_ENGINES];
  86. };
  87. enum intel_uc_fw_status {
  88. INTEL_UC_FIRMWARE_FAIL = -1,
  89. INTEL_UC_FIRMWARE_NONE = 0,
  90. INTEL_UC_FIRMWARE_PENDING,
  91. INTEL_UC_FIRMWARE_SUCCESS
  92. };
  93. enum intel_uc_fw_type {
  94. INTEL_UC_FW_TYPE_GUC,
  95. INTEL_UC_FW_TYPE_HUC
  96. };
  97. /*
  98. * This structure encapsulates all the data needed during the process
  99. * of fetching, caching, and loading the firmware image into the GuC.
  100. */
  101. struct intel_uc_fw {
  102. const char *path;
  103. size_t size;
  104. struct drm_i915_gem_object *obj;
  105. enum intel_uc_fw_status fetch_status;
  106. enum intel_uc_fw_status load_status;
  107. uint16_t major_ver_wanted;
  108. uint16_t minor_ver_wanted;
  109. uint16_t major_ver_found;
  110. uint16_t minor_ver_found;
  111. enum intel_uc_fw_type fw;
  112. uint32_t header_size;
  113. uint32_t header_offset;
  114. uint32_t rsa_size;
  115. uint32_t rsa_offset;
  116. uint32_t ucode_size;
  117. uint32_t ucode_offset;
  118. };
  119. struct intel_guc_log {
  120. uint32_t flags;
  121. struct i915_vma *vma;
  122. void *buf_addr;
  123. struct workqueue_struct *flush_wq;
  124. struct work_struct flush_work;
  125. struct rchan *relay_chan;
  126. /* logging related stats */
  127. u32 capture_miss_count;
  128. u32 flush_interrupt_count;
  129. u32 prev_overflow_count[GUC_MAX_LOG_BUFFER];
  130. u32 total_overflow_count[GUC_MAX_LOG_BUFFER];
  131. u32 flush_count[GUC_MAX_LOG_BUFFER];
  132. };
  133. struct intel_guc {
  134. struct intel_uc_fw fw;
  135. struct intel_guc_log log;
  136. /* intel_guc_recv interrupt related state */
  137. bool interrupts_enabled;
  138. struct i915_vma *ads_vma;
  139. struct i915_vma *ctx_pool_vma;
  140. struct ida ctx_ids;
  141. struct i915_guc_client *execbuf_client;
  142. DECLARE_BITMAP(doorbell_bitmap, GUC_MAX_DOORBELLS);
  143. uint32_t db_cacheline; /* Cyclic counter mod pagesize */
  144. /* Action status & statistics */
  145. uint64_t action_count; /* Total commands issued */
  146. uint32_t action_cmd; /* Last command word */
  147. uint32_t action_status; /* Last return status */
  148. uint32_t action_fail; /* Total number of failures */
  149. int32_t action_err; /* Last error code */
  150. uint64_t submissions[I915_NUM_ENGINES];
  151. uint32_t last_seqno[I915_NUM_ENGINES];
  152. /* To serialize the intel_guc_send actions */
  153. struct mutex send_mutex;
  154. };
  155. struct intel_huc {
  156. /* Generic uC firmware management */
  157. struct intel_uc_fw fw;
  158. /* HuC-specific additions */
  159. };
  160. /* intel_uc.c */
  161. void intel_uc_init_early(struct drm_i915_private *dev_priv);
  162. int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len);
  163. int intel_guc_sample_forcewake(struct intel_guc *guc);
  164. /* intel_guc_loader.c */
  165. extern void intel_guc_init(struct drm_i915_private *dev_priv);
  166. extern int intel_guc_setup(struct drm_i915_private *dev_priv);
  167. extern void intel_guc_fini(struct drm_i915_private *dev_priv);
  168. extern const char *intel_uc_fw_status_repr(enum intel_uc_fw_status status);
  169. extern int intel_guc_suspend(struct drm_i915_private *dev_priv);
  170. extern int intel_guc_resume(struct drm_i915_private *dev_priv);
  171. void intel_uc_fw_fetch(struct drm_i915_private *dev_priv,
  172. struct intel_uc_fw *uc_fw);
  173. u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv);
  174. /* i915_guc_submission.c */
  175. int i915_guc_submission_init(struct drm_i915_private *dev_priv);
  176. int i915_guc_submission_enable(struct drm_i915_private *dev_priv);
  177. int i915_guc_wq_reserve(struct drm_i915_gem_request *rq);
  178. void i915_guc_wq_unreserve(struct drm_i915_gem_request *request);
  179. void i915_guc_submission_disable(struct drm_i915_private *dev_priv);
  180. void i915_guc_submission_fini(struct drm_i915_private *dev_priv);
  181. struct i915_vma *intel_guc_allocate_vma(struct intel_guc *guc, u32 size);
  182. /* intel_guc_log.c */
  183. void intel_guc_log_create(struct intel_guc *guc);
  184. void i915_guc_log_register(struct drm_i915_private *dev_priv);
  185. void i915_guc_log_unregister(struct drm_i915_private *dev_priv);
  186. int i915_guc_log_control(struct drm_i915_private *dev_priv, u64 control_val);
  187. static inline u32 guc_ggtt_offset(struct i915_vma *vma)
  188. {
  189. u32 offset = i915_ggtt_offset(vma);
  190. GEM_BUG_ON(offset < GUC_WOPCM_TOP);
  191. GEM_BUG_ON(range_overflows_t(u64, offset, vma->size, GUC_GGTT_TOP));
  192. return offset;
  193. }
  194. /* intel_huc.c */
  195. void intel_huc_init(struct drm_i915_private *dev_priv);
  196. void intel_huc_fini(struct drm_i915_private *dev_priv);
  197. int intel_huc_load(struct drm_i915_private *dev_priv);
  198. void intel_guc_auth_huc(struct drm_i915_private *dev_priv);
  199. #endif