msm_gpu.h 6.2 KB

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