intel_uncore.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright © 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_UNCORE_H__
  25. #define __INTEL_UNCORE_H__
  26. #include <linux/spinlock.h>
  27. #include <linux/notifier.h>
  28. #include <linux/hrtimer.h>
  29. #include "i915_reg.h"
  30. struct drm_i915_private;
  31. enum forcewake_domain_id {
  32. FW_DOMAIN_ID_RENDER = 0,
  33. FW_DOMAIN_ID_BLITTER,
  34. FW_DOMAIN_ID_MEDIA,
  35. FW_DOMAIN_ID_COUNT
  36. };
  37. enum forcewake_domains {
  38. FORCEWAKE_RENDER = BIT(FW_DOMAIN_ID_RENDER),
  39. FORCEWAKE_BLITTER = BIT(FW_DOMAIN_ID_BLITTER),
  40. FORCEWAKE_MEDIA = BIT(FW_DOMAIN_ID_MEDIA),
  41. FORCEWAKE_ALL = (FORCEWAKE_RENDER |
  42. FORCEWAKE_BLITTER |
  43. FORCEWAKE_MEDIA)
  44. };
  45. struct intel_uncore_funcs {
  46. void (*force_wake_get)(struct drm_i915_private *dev_priv,
  47. enum forcewake_domains domains);
  48. void (*force_wake_put)(struct drm_i915_private *dev_priv,
  49. enum forcewake_domains domains);
  50. uint8_t (*mmio_readb)(struct drm_i915_private *dev_priv,
  51. i915_reg_t r, bool trace);
  52. uint16_t (*mmio_readw)(struct drm_i915_private *dev_priv,
  53. i915_reg_t r, bool trace);
  54. uint32_t (*mmio_readl)(struct drm_i915_private *dev_priv,
  55. i915_reg_t r, bool trace);
  56. uint64_t (*mmio_readq)(struct drm_i915_private *dev_priv,
  57. i915_reg_t r, bool trace);
  58. void (*mmio_writeb)(struct drm_i915_private *dev_priv,
  59. i915_reg_t r, uint8_t val, bool trace);
  60. void (*mmio_writew)(struct drm_i915_private *dev_priv,
  61. i915_reg_t r, uint16_t val, bool trace);
  62. void (*mmio_writel)(struct drm_i915_private *dev_priv,
  63. i915_reg_t r, uint32_t val, bool trace);
  64. };
  65. struct intel_forcewake_range {
  66. u32 start;
  67. u32 end;
  68. enum forcewake_domains domains;
  69. };
  70. struct intel_uncore {
  71. spinlock_t lock; /** lock is also taken in irq contexts. */
  72. const struct intel_forcewake_range *fw_domains_table;
  73. unsigned int fw_domains_table_entries;
  74. struct notifier_block pmic_bus_access_nb;
  75. struct intel_uncore_funcs funcs;
  76. unsigned int fifo_count;
  77. enum forcewake_domains fw_domains;
  78. enum forcewake_domains fw_domains_active;
  79. u32 fw_set;
  80. u32 fw_clear;
  81. u32 fw_reset;
  82. struct intel_uncore_forcewake_domain {
  83. enum forcewake_domain_id id;
  84. enum forcewake_domains mask;
  85. unsigned int wake_count;
  86. bool active;
  87. struct hrtimer timer;
  88. i915_reg_t reg_set;
  89. i915_reg_t reg_ack;
  90. } fw_domain[FW_DOMAIN_ID_COUNT];
  91. struct {
  92. unsigned int count;
  93. int saved_mmio_check;
  94. int saved_mmio_debug;
  95. } user_forcewake;
  96. int unclaimed_mmio_check;
  97. };
  98. /* Iterate over initialised fw domains */
  99. #define for_each_fw_domain_masked(domain__, mask__, dev_priv__, tmp__) \
  100. for (tmp__ = (mask__); \
  101. tmp__ ? (domain__ = &(dev_priv__)->uncore.fw_domain[__mask_next_bit(tmp__)]), 1 : 0;)
  102. #define for_each_fw_domain(domain__, dev_priv__, tmp__) \
  103. for_each_fw_domain_masked(domain__, (dev_priv__)->uncore.fw_domains, dev_priv__, tmp__)
  104. void intel_uncore_sanitize(struct drm_i915_private *dev_priv);
  105. void intel_uncore_init(struct drm_i915_private *dev_priv);
  106. bool intel_uncore_unclaimed_mmio(struct drm_i915_private *dev_priv);
  107. bool intel_uncore_arm_unclaimed_mmio_detection(struct drm_i915_private *dev_priv);
  108. void intel_uncore_fini(struct drm_i915_private *dev_priv);
  109. void intel_uncore_suspend(struct drm_i915_private *dev_priv);
  110. void intel_uncore_resume_early(struct drm_i915_private *dev_priv);
  111. void intel_uncore_runtime_resume(struct drm_i915_private *dev_priv);
  112. u64 intel_uncore_edram_size(struct drm_i915_private *dev_priv);
  113. void assert_forcewakes_inactive(struct drm_i915_private *dev_priv);
  114. void assert_forcewakes_active(struct drm_i915_private *dev_priv,
  115. enum forcewake_domains fw_domains);
  116. const char *intel_uncore_forcewake_domain_to_str(const enum forcewake_domain_id id);
  117. enum forcewake_domains
  118. intel_uncore_forcewake_for_reg(struct drm_i915_private *dev_priv,
  119. i915_reg_t reg, unsigned int op);
  120. #define FW_REG_READ (1)
  121. #define FW_REG_WRITE (2)
  122. void intel_uncore_forcewake_get(struct drm_i915_private *dev_priv,
  123. enum forcewake_domains domains);
  124. void intel_uncore_forcewake_put(struct drm_i915_private *dev_priv,
  125. enum forcewake_domains domains);
  126. /* Like above but the caller must manage the uncore.lock itself.
  127. * Must be used with I915_READ_FW and friends.
  128. */
  129. void intel_uncore_forcewake_get__locked(struct drm_i915_private *dev_priv,
  130. enum forcewake_domains domains);
  131. void intel_uncore_forcewake_put__locked(struct drm_i915_private *dev_priv,
  132. enum forcewake_domains domains);
  133. void intel_uncore_forcewake_user_get(struct drm_i915_private *dev_priv);
  134. void intel_uncore_forcewake_user_put(struct drm_i915_private *dev_priv);
  135. int intel_wait_for_register(struct drm_i915_private *dev_priv,
  136. i915_reg_t reg,
  137. u32 mask,
  138. u32 value,
  139. unsigned int timeout_ms);
  140. int __intel_wait_for_register_fw(struct drm_i915_private *dev_priv,
  141. i915_reg_t reg,
  142. u32 mask,
  143. u32 value,
  144. unsigned int fast_timeout_us,
  145. unsigned int slow_timeout_ms,
  146. u32 *out_value);
  147. static inline
  148. int intel_wait_for_register_fw(struct drm_i915_private *dev_priv,
  149. i915_reg_t reg,
  150. u32 mask,
  151. u32 value,
  152. unsigned int timeout_ms)
  153. {
  154. return __intel_wait_for_register_fw(dev_priv, reg, mask, value,
  155. 2, timeout_ms, NULL);
  156. }
  157. #endif /* !__INTEL_UNCORE_H__ */