intel_uc.h 8.8 KB

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