msm_gpu.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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_ringbuffer.h"
  23. struct msm_gem_submit;
  24. struct msm_gpu_perfcntr;
  25. /* So far, with hardware that I've seen to date, we can have:
  26. * + zero, one, or two z180 2d cores
  27. * + a3xx or a2xx 3d core, which share a common CP (the firmware
  28. * for the CP seems to implement some different PM4 packet types
  29. * but the basics of cmdstream submission are the same)
  30. *
  31. * Which means that the eventual complete "class" hierarchy, once
  32. * support for all past and present hw is in place, becomes:
  33. * + msm_gpu
  34. * + adreno_gpu
  35. * + a3xx_gpu
  36. * + a2xx_gpu
  37. * + z180_gpu
  38. */
  39. struct msm_gpu_funcs {
  40. int (*get_param)(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
  41. int (*hw_init)(struct msm_gpu *gpu);
  42. int (*pm_suspend)(struct msm_gpu *gpu);
  43. int (*pm_resume)(struct msm_gpu *gpu);
  44. int (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  45. struct msm_file_private *ctx);
  46. void (*flush)(struct msm_gpu *gpu);
  47. void (*idle)(struct msm_gpu *gpu);
  48. irqreturn_t (*irq)(struct msm_gpu *irq);
  49. uint32_t (*last_fence)(struct msm_gpu *gpu);
  50. void (*recover)(struct msm_gpu *gpu);
  51. void (*destroy)(struct msm_gpu *gpu);
  52. #ifdef CONFIG_DEBUG_FS
  53. /* show GPU status in debugfs: */
  54. void (*show)(struct msm_gpu *gpu, struct seq_file *m);
  55. #endif
  56. };
  57. struct msm_gpu {
  58. const char *name;
  59. struct drm_device *dev;
  60. const struct msm_gpu_funcs *funcs;
  61. /* performance counters (hw & sw): */
  62. spinlock_t perf_lock;
  63. bool perfcntr_active;
  64. struct {
  65. bool active;
  66. ktime_t time;
  67. } last_sample;
  68. uint32_t totaltime, activetime; /* sw counters */
  69. uint32_t last_cntrs[5]; /* hw counters */
  70. const struct msm_gpu_perfcntr *perfcntrs;
  71. uint32_t num_perfcntrs;
  72. struct msm_ringbuffer *rb;
  73. uint32_t rb_iova;
  74. /* list of GEM active objects: */
  75. struct list_head active_list;
  76. uint32_t submitted_fence;
  77. /* is gpu powered/active? */
  78. int active_cnt;
  79. bool inactive;
  80. /* worker for handling active-list retiring: */
  81. struct work_struct retire_work;
  82. void __iomem *mmio;
  83. int irq;
  84. struct msm_mmu *mmu;
  85. int id;
  86. /* Power Control: */
  87. struct regulator *gpu_reg, *gpu_cx;
  88. struct clk *ebi1_clk, *grp_clks[6];
  89. uint32_t fast_rate, slow_rate, bus_freq;
  90. #ifdef DOWNSTREAM_CONFIG_MSM_BUS_SCALING
  91. struct msm_bus_scale_pdata *bus_scale_table;
  92. uint32_t bsc;
  93. #endif
  94. /* Hang and Inactivity Detection:
  95. */
  96. #define DRM_MSM_INACTIVE_PERIOD 66 /* in ms (roughly four frames) */
  97. #define DRM_MSM_INACTIVE_JIFFIES msecs_to_jiffies(DRM_MSM_INACTIVE_PERIOD)
  98. struct timer_list inactive_timer;
  99. struct work_struct inactive_work;
  100. #define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
  101. #define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
  102. struct timer_list hangcheck_timer;
  103. uint32_t hangcheck_fence;
  104. struct work_struct recover_work;
  105. struct list_head submit_list;
  106. };
  107. static inline bool msm_gpu_active(struct msm_gpu *gpu)
  108. {
  109. return gpu->submitted_fence > gpu->funcs->last_fence(gpu);
  110. }
  111. /* Perf-Counters:
  112. * The select_reg and select_val are just there for the benefit of the child
  113. * class that actually enables the perf counter.. but msm_gpu base class
  114. * will handle sampling/displaying the counters.
  115. */
  116. struct msm_gpu_perfcntr {
  117. uint32_t select_reg;
  118. uint32_t sample_reg;
  119. uint32_t select_val;
  120. const char *name;
  121. };
  122. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  123. {
  124. msm_writel(data, gpu->mmio + (reg << 2));
  125. }
  126. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  127. {
  128. return msm_readl(gpu->mmio + (reg << 2));
  129. }
  130. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  131. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  132. void msm_gpu_perfcntr_start(struct msm_gpu *gpu);
  133. void msm_gpu_perfcntr_stop(struct msm_gpu *gpu);
  134. int msm_gpu_perfcntr_sample(struct msm_gpu *gpu, uint32_t *activetime,
  135. uint32_t *totaltime, uint32_t ncntrs, uint32_t *cntrs);
  136. void msm_gpu_retire(struct msm_gpu *gpu);
  137. int msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  138. struct msm_file_private *ctx);
  139. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  140. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  141. const char *name, const char *ioname, const char *irqname, int ringsz);
  142. void msm_gpu_cleanup(struct msm_gpu *gpu);
  143. struct msm_gpu *adreno_load_gpu(struct drm_device *dev);
  144. void __init adreno_register(void);
  145. void __exit adreno_unregister(void);
  146. #endif /* __MSM_GPU_H__ */