msm_gpu.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. void (*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. const struct msm_gpu_funcs *funcs;
  62. /* performance counters (hw & sw): */
  63. spinlock_t perf_lock;
  64. bool perfcntr_active;
  65. struct {
  66. bool active;
  67. ktime_t time;
  68. } last_sample;
  69. uint32_t totaltime, activetime; /* sw counters */
  70. uint32_t last_cntrs[5]; /* hw counters */
  71. const struct msm_gpu_perfcntr *perfcntrs;
  72. uint32_t num_perfcntrs;
  73. /* ringbuffer: */
  74. struct msm_ringbuffer *rb;
  75. uint32_t rb_iova;
  76. /* list of GEM active objects: */
  77. struct list_head active_list;
  78. /* fencing: */
  79. struct msm_fence_context *fctx;
  80. /* is gpu powered/active? */
  81. int active_cnt;
  82. bool inactive;
  83. /* worker for handling active-list retiring: */
  84. struct work_struct retire_work;
  85. void __iomem *mmio;
  86. int irq;
  87. struct msm_mmu *mmu;
  88. int id;
  89. /* Power Control: */
  90. struct regulator *gpu_reg, *gpu_cx;
  91. struct clk *ebi1_clk, *grp_clks[6];
  92. uint32_t fast_rate, slow_rate, bus_freq;
  93. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  94. struct msm_bus_scale_pdata *bus_scale_table;
  95. uint32_t bsc;
  96. #endif
  97. /* Hang and Inactivity Detection:
  98. */
  99. #define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
  100. #define DRM_MSM_INACTIVE_JIFFIES msecs_to_jiffies(DRM_MSM_INACTIVE_PERIOD)
  101. struct timer_list inactive_timer;
  102. struct work_struct inactive_work;
  103. #define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
  104. #define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
  105. struct timer_list hangcheck_timer;
  106. uint32_t hangcheck_fence;
  107. struct work_struct recover_work;
  108. struct list_head submit_list;
  109. };
  110. static inline bool msm_gpu_active(struct msm_gpu *gpu)
  111. {
  112. return gpu->fctx->last_fence > gpu->funcs->last_fence(gpu);
  113. }
  114. /* Perf-Counters:
  115. * The select_reg and select_val are just there for the benefit of the child
  116. * class that actually enables the perf counter.. but msm_gpu base class
  117. * will handle sampling/displaying the counters.
  118. */
  119. struct msm_gpu_perfcntr {
  120. uint32_t select_reg;
  121. uint32_t sample_reg;
  122. uint32_t select_val;
  123. const char *name;
  124. };
  125. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  126. {
  127. msm_writel(data, gpu->mmio + (reg << 2));
  128. }
  129. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  130. {
  131. return msm_readl(gpu->mmio + (reg << 2));
  132. }
  133. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  134. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  135. void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
  136. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
  137. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  138. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
  139. void msm_gpu_retire(struct msm_gpu *gpu);
  140. void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  141. struct msm_file_private *ctx);
  142. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  143. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  144. const char *name, const char *ioname, const char *irqname, int ringsz);
  145. void msm_gpu_cleanup(struct msm_gpu *gpu);
  146. struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
  147. void __init adreno_register(void);
  148. void __exit adreno_unregister(void);
  149. #endif /* __MSM_GPU_H__ */