msm_gpu.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 nr_rings;
  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, struct msm_ringbuffer *ring);
  55. irqreturn_t (*irq)(struct msm_gpu *irq);
  56. struct msm_ringbuffer *(*active_ring)(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. struct msm_ringbuffer *rb[MSM_GPU_MAX_RINGS];
  81. int nr_rings;
  82. /* list of GEM active objects: */
  83. struct list_head active_list;
  84. /* does gpu need hw_init? */
  85. bool needs_hw_init;
  86. /* worker for handling active-list retiring: */
  87. struct work_struct retire_work;
  88. void __iomem *mmio;
  89. int irq;
  90. struct msm_gem_address_space *aspace;
  91. /* Power Control: */
  92. struct regulator *gpu_reg, *gpu_cx;
  93. struct clk **grp_clks;
  94. int nr_clocks;
  95. struct clk *ebi1_clk, *core_clk, *rbbmtimer_clk;
  96. uint32_t fast_rate, bus_freq;
  97. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  98. struct msm_bus_scale_pdata *bus_scale_table;
  99. uint32_t bsc;
  100. #endif
  101. /* Hang and Inactivity Detection:
  102. */
  103. #define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
  104. #define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
  105. #define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
  106. struct timer_list hangcheck_timer;
  107. struct work_struct recover_work;
  108. struct drm_gem_object *memptrs_bo;
  109. };
  110. /* It turns out that all targets use the same ringbuffer size */
  111. #define MSM_GPU_RINGBUFFER_SZ SZ_32K
  112. #define MSM_GPU_RINGBUFFER_BLKSIZE 32
  113. #define MSM_GPU_RB_CNTL_DEFAULT \
  114. (AXXX_CP_RB_CNTL_BUFSZ(ilog2(MSM_GPU_RINGBUFFER_SZ / 8)) | \
  115. AXXX_CP_RB_CNTL_BLKSZ(ilog2(MSM_GPU_RINGBUFFER_BLKSIZE / 8)))
  116. static inline bool msm_gpu_active(struct msm_gpu *gpu)
  117. {
  118. int i;
  119. for (i = 0; i < gpu->nr_rings; i++) {
  120. struct msm_ringbuffer *ring = gpu->rb[i];
  121. if (ring->seqno > ring->memptrs->fence)
  122. return true;
  123. }
  124. return false;
  125. }
  126. /* Perf-Counters:
  127. * The select_reg and select_val are just there for the benefit of the child
  128. * class that actually enables the perf counter.. but msm_gpu base class
  129. * will handle sampling/displaying the counters.
  130. */
  131. struct msm_gpu_perfcntr {
  132. uint32_t select_reg;
  133. uint32_t sample_reg;
  134. uint32_t select_val;
  135. const char *name;
  136. };
  137. struct msm_gpu_submitqueue {
  138. int id;
  139. u32 flags;
  140. u32 prio;
  141. int faults;
  142. struct list_head node;
  143. struct kref ref;
  144. };
  145. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  146. {
  147. msm_writel(data, gpu->mmio + (reg << 2));
  148. }
  149. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  150. {
  151. return msm_readl(gpu->mmio + (reg << 2));
  152. }
  153. static inline void gpu_rmw(struct msm_gpu *gpu, u32 reg, u32 mask, u32 or)
  154. {
  155. uint32_t val = gpu_read(gpu, reg);
  156. val &= ~mask;
  157. gpu_write(gpu, reg, val | or);
  158. }
  159. static inline u64 gpu_read64(struct msm_gpu *gpu, u32 lo, u32 hi)
  160. {
  161. u64 val;
  162. /*
  163. * Why not a readq here? Two reasons: 1) many of the LO registers are
  164. * not quad word aligned and 2) the GPU hardware designers have a bit
  165. * of a history of putting registers where they fit, especially in
  166. * spins. The longer a GPU family goes the higher the chance that
  167. * we'll get burned. We could do a series of validity checks if we
  168. * wanted to, but really is a readq() that much better? Nah.
  169. */
  170. /*
  171. * For some lo/hi registers (like perfcounters), the hi value is latched
  172. * when the lo is read, so make sure to read the lo first to trigger
  173. * that
  174. */
  175. val = (u64) msm_readl(gpu->mmio + (lo << 2));
  176. val |= ((u64) msm_readl(gpu->mmio + (hi << 2)) << 32);
  177. return val;
  178. }
  179. static inline void gpu_write64(struct msm_gpu *gpu, u32 lo, u32 hi, u64 val)
  180. {
  181. /* Why not a writeq here? Read the screed above */
  182. msm_writel(lower_32_bits(val), gpu->mmio + (lo << 2));
  183. msm_writel(upper_32_bits(val), gpu->mmio + (hi << 2));
  184. }
  185. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  186. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  187. int msm_gpu_hw_init(struct msm_gpu *gpu);
  188. void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
  189. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
  190. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  191. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
  192. void msm_gpu_retire(struct msm_gpu *gpu);
  193. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  194. struct msm_file_private *ctx);
  195. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  196. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  197. const char *name, struct msm_gpu_config *config);
  198. void msm_gpu_cleanup(struct msm_gpu *gpu);
  199. struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
  200. void __init adreno_register(void);
  201. void __exit adreno_unregister(void);
  202. static inline void msm_submitqueue_put(struct msm_gpu_submitqueue *queue)
  203. {
  204. if (queue)
  205. kref_put(&queue->ref, msm_submitqueue_destroy);
  206. }
  207. #endif /* __MSM_GPU_H__ */