msm_gpu.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. * Copyright (C) 2013 Red Hat
  3. * Author: Rob Clark <robdclark@gmail.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published by
  7. * the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __MSM_GPU_H__
  18. #define __MSM_GPU_H__
  19. #include <linux/clk.h>
  20. #include <linux/regulator/consumer.h>
  21. #include "msm_drv.h"
  22. #include "msm_fence.h"
  23. #include "msm_ringbuffer.h"
  24. struct msm_gem_submit;
  25. struct msm_gpu_perfcntr;
  26. struct msm_gpu_config {
  27. const char *ioname;
  28. const char *irqname;
  29. uint64_t va_start;
  30. uint64_t va_end;
  31. unsigned int ringsz;
  32. };
  33. /* So far, with hardware that I've seen to date, we can have:
  34. * + zero, one, or two z180 2d cores
  35. * + a3xx or a2xx 3d core, which share a common CP (the firmware
  36. * for the CP seems to implement some different PM4 packet types
  37. * but the basics of cmdstream submission are the same)
  38. *
  39. * Which means that the eventual complete "class" hierarchy, once
  40. * support for all past and present hw is in place, becomes:
  41. * + msm_gpu
  42. * + adreno_gpu
  43. * + a3xx_gpu
  44. * + a2xx_gpu
  45. * + z180_gpu
  46. */
  47. struct msm_gpu_funcs {
  48. int (*get_param)(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
  49. int (*hw_init)(struct msm_gpu *gpu);
  50. int (*pm_suspend)(struct msm_gpu *gpu);
  51. int (*pm_resume)(struct msm_gpu *gpu);
  52. void (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  53. struct msm_file_private *ctx);
  54. void (*flush)(struct msm_gpu *gpu);
  55. irqreturn_t (*irq)(struct msm_gpu *irq);
  56. uint32_t (*last_fence)(struct msm_gpu *gpu);
  57. void (*recover)(struct msm_gpu *gpu);
  58. void (*destroy)(struct msm_gpu *gpu);
  59. #ifdef CONFIG_DEBUG_FS
  60. /* show GPU status in debugfs: */
  61. void (*show)(struct msm_gpu *gpu, struct seq_file *m);
  62. #endif
  63. };
  64. struct msm_gpu {
  65. const char *name;
  66. struct drm_device *dev;
  67. struct platform_device *pdev;
  68. const struct msm_gpu_funcs *funcs;
  69. /* performance counters (hw & sw): */
  70. spinlock_t perf_lock;
  71. bool perfcntr_active;
  72. struct {
  73. bool active;
  74. ktime_t time;
  75. } last_sample;
  76. uint32_t totaltime, activetime; /* sw counters */
  77. uint32_t last_cntrs[5]; /* hw counters */
  78. const struct msm_gpu_perfcntr *perfcntrs;
  79. uint32_t num_perfcntrs;
  80. /* ringbuffer: */
  81. struct msm_ringbuffer *rb;
  82. uint64_t rb_iova;
  83. /* list of GEM active objects: */
  84. struct list_head active_list;
  85. /* fencing: */
  86. struct msm_fence_context *fctx;
  87. /* does gpu need hw_init? */
  88. bool needs_hw_init;
  89. /* worker for handling active-list retiring: */
  90. struct work_struct retire_work;
  91. void __iomem *mmio;
  92. int irq;
  93. struct msm_gem_address_space *aspace;
  94. /* Power Control: */
  95. struct regulator *gpu_reg, *gpu_cx;
  96. struct clk **grp_clks;
  97. int nr_clocks;
  98. struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk;
  99. uint32_t fast_rate, bus_freq;
  100. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  101. struct msm_bus_scale_pdata *bus_scale_table;
  102. uint32_t bsc;
  103. #endif
  104. /* Hang and Inactivity Detection:
  105. */
  106. #define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
  107. #define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
  108. #define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
  109. struct timer_list hangcheck_timer;
  110. uint32_t hangcheck_fence;
  111. struct work_struct recover_work;
  112. struct list_head submit_list;
  113. };
  114. static inline bool msm_gpu_active(struct msm_gpu *gpu)
  115. {
  116. return gpu->fctx->last_fence > gpu->funcs->last_fence(gpu);
  117. }
  118. /* Perf-Counters:
  119. * The select_reg and select_val are just there for the benefit of the child
  120. * class that actually enables the perf counter.. but msm_gpu base class
  121. * will handle sampling/displaying the counters.
  122. */
  123. struct msm_gpu_perfcntr {
  124. uint32_t select_reg;
  125. uint32_t sample_reg;
  126. uint32_t select_val;
  127. const char *name;
  128. };
  129. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  130. {
  131. msm_writel(data, gpu->mmio + (reg << 2));
  132. }
  133. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  134. {
  135. return msm_readl(gpu->mmio + (reg << 2));
  136. }
  137. static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
  138. {
  139. uint32_t val = gpu_read(gpu, reg);
  140. val &= ~mask;
  141. gpu_write(gpu, reg, val | or);
  142. }
  143. static inline u64 gpu_read64(struct msm_gpu *gpu, u32 lo, u32 hi)
  144. {
  145. u64 val;
  146. /*
  147. * Why not a readq here? Two reasons: 1) many of the LO registers are
  148. * not quad word aligned and 2) the GPU hardware designers have a bit
  149. * of a history of putting registers where they fit, especially in
  150. * spins. The longer a GPU family goes the higher the chance that
  151. * we'll get burned. We could do a series of validity checks if we
  152. * wanted to, but really is a readq() that much better? Nah.
  153. */
  154. /*
  155. * For some lo/hi registers (like perfcounters), the hi value is latched
  156. * when the lo is read, so make sure to read the lo first to trigger
  157. * that
  158. */
  159. val = (u64) msm_readl(gpu->mmio + (lo << 2));
  160. val |= ((u64) msm_readl(gpu->mmio + (hi << 2)) << 32);
  161. return val;
  162. }
  163. static inline void gpu_write64(struct msm_gpu *gpu, u32 lo, u32 hi, u64 val)
  164. {
  165. /* Why not a writeq here? Read the screed above */
  166. msm_writel(lower_32_bits(val), gpu->mmio + (lo << 2));
  167. msm_writel(upper_32_bits(val), gpu->mmio + (hi << 2));
  168. }
  169. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  170. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  171. int msm_gpu_hw_init(struct msm_gpu *gpu);
  172. void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
  173. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
  174. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  175. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
  176. void msm_gpu_retire(struct msm_gpu *gpu);
  177. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  178. struct msm_file_private *ctx);
  179. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  180. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  181. const char *name, struct msm_gpu_config *config);
  182. void msm_gpu_cleanup(struct msm_gpu *gpu);
  183. struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
  184. void __init adreno_register(void);
  185. void __exit adreno_unregister(void);
  186. #endif /* __MSM_GPU_H__ */