intel_lrc.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* SPDX-License-Identifier: MIT */
  2. /*
  3. * Copyright © 2014 Intel Corporation
  4. */
  5. #ifndef __INTEL_LRC_H__
  6. #define __INTEL_LRC_H__
  7. #include "i915_priolist_types.h"
  8. #include <linux/bitfield.h>
  9. #include <linux/types.h>
  10. #include "intel_context.h"
  11. struct drm_i915_gem_object;
  12. struct i915_gem_ww_ctx;
  13. struct intel_engine_cs;
  14. struct intel_ring;
  15. struct kref;
  16. /* At the start of the context image is its per-process HWS page */
  17. #define LRC_PPHWSP_PN (0)
  18. #define LRC_PPHWSP_SZ (1)
  19. /* After the PPHWSP we have the logical state for the context */
  20. #define LRC_STATE_PN (LRC_PPHWSP_PN + LRC_PPHWSP_SZ)
  21. #define LRC_STATE_OFFSET (LRC_STATE_PN * PAGE_SIZE)
  22. /* Space within PPHWSP reserved to be used as scratch */
  23. #define LRC_PPHWSP_SCRATCH 0x34
  24. #define LRC_PPHWSP_SCRATCH_ADDR (LRC_PPHWSP_SCRATCH * sizeof(u32))
  25. void lrc_init_wa_ctx(struct intel_engine_cs *engine);
  26. void lrc_fini_wa_ctx(struct intel_engine_cs *engine);
  27. int lrc_alloc(struct intel_context *ce,
  28. struct intel_engine_cs *engine);
  29. void lrc_reset(struct intel_context *ce);
  30. void lrc_fini(struct intel_context *ce);
  31. void lrc_destroy(struct kref *kref);
  32. int
  33. lrc_pre_pin(struct intel_context *ce,
  34. struct intel_engine_cs *engine,
  35. struct i915_gem_ww_ctx *ww,
  36. void **vaddr);
  37. int
  38. lrc_pin(struct intel_context *ce,
  39. struct intel_engine_cs *engine,
  40. void *vaddr);
  41. void lrc_unpin(struct intel_context *ce);
  42. void lrc_post_unpin(struct intel_context *ce);
  43. void lrc_init_state(struct intel_context *ce,
  44. struct intel_engine_cs *engine,
  45. void *state);
  46. void lrc_init_regs(const struct intel_context *ce,
  47. const struct intel_engine_cs *engine,
  48. bool clear);
  49. void lrc_reset_regs(const struct intel_context *ce,
  50. const struct intel_engine_cs *engine);
  51. u32 lrc_update_regs(const struct intel_context *ce,
  52. const struct intel_engine_cs *engine,
  53. u32 head);
  54. void lrc_update_offsets(struct intel_context *ce,
  55. struct intel_engine_cs *engine);
  56. void lrc_check_regs(const struct intel_context *ce,
  57. const struct intel_engine_cs *engine,
  58. const char *when);
  59. void lrc_update_runtime(struct intel_context *ce);
  60. enum {
  61. INTEL_ADVANCED_CONTEXT = 0,
  62. INTEL_LEGACY_32B_CONTEXT,
  63. INTEL_ADVANCED_AD_CONTEXT,
  64. INTEL_LEGACY_64B_CONTEXT
  65. };
  66. enum {
  67. FAULT_AND_HANG = 0,
  68. FAULT_AND_HALT, /* Debug only */
  69. FAULT_AND_STREAM,
  70. FAULT_AND_CONTINUE /* Unsupported */
  71. };
  72. #define CTX_GTT_ADDRESS_MASK GENMASK(31, 12)
  73. #define GEN8_CTX_VALID (1 << 0)
  74. #define GEN8_CTX_FORCE_PD_RESTORE (1 << 1)
  75. #define GEN8_CTX_FORCE_RESTORE (1 << 2)
  76. #define GEN8_CTX_L3LLC_COHERENT (1 << 5)
  77. #define GEN8_CTX_PRIVILEGE (1 << 8)
  78. #define GEN8_CTX_ADDRESSING_MODE_SHIFT 3
  79. #define GEN12_CTX_PRIORITY_MASK GENMASK(10, 9)
  80. #define GEN12_CTX_PRIORITY_HIGH FIELD_PREP(GEN12_CTX_PRIORITY_MASK, 2)
  81. #define GEN12_CTX_PRIORITY_NORMAL FIELD_PREP(GEN12_CTX_PRIORITY_MASK, 1)
  82. #define GEN12_CTX_PRIORITY_LOW FIELD_PREP(GEN12_CTX_PRIORITY_MASK, 0)
  83. #define GEN8_CTX_ID_SHIFT 32
  84. #define GEN8_CTX_ID_WIDTH 21
  85. #define GEN11_SW_CTX_ID_SHIFT 37
  86. #define GEN11_SW_CTX_ID_WIDTH 11
  87. #define GEN11_ENGINE_CLASS_SHIFT 61
  88. #define GEN11_ENGINE_CLASS_WIDTH 3
  89. #define GEN11_ENGINE_INSTANCE_SHIFT 48
  90. #define GEN11_ENGINE_INSTANCE_WIDTH 6
  91. #define XEHP_SW_CTX_ID_SHIFT 39
  92. #define XEHP_SW_CTX_ID_WIDTH 16
  93. #define XEHP_SW_COUNTER_SHIFT 58
  94. #define XEHP_SW_COUNTER_WIDTH 6
  95. #define GEN12_GUC_SW_CTX_ID_SHIFT 39
  96. #define GEN12_GUC_SW_CTX_ID_WIDTH 16
  97. static inline void lrc_runtime_start(struct intel_context *ce)
  98. {
  99. struct intel_context_stats *stats = &ce->stats;
  100. if (intel_context_is_barrier(ce))
  101. return;
  102. if (stats->active)
  103. return;
  104. WRITE_ONCE(stats->active, intel_context_clock());
  105. }
  106. static inline void lrc_runtime_stop(struct intel_context *ce)
  107. {
  108. struct intel_context_stats *stats = &ce->stats;
  109. if (!stats->active)
  110. return;
  111. lrc_update_runtime(ce);
  112. WRITE_ONCE(stats->active, 0);
  113. }
  114. #define DG2_PREDICATE_RESULT_WA (PAGE_SIZE - sizeof(u64))
  115. #define DG2_PREDICATE_RESULT_BB (2048)
  116. u32 lrc_indirect_bb(const struct intel_context *ce);
  117. #endif /* __INTEL_LRC_H__ */