msm_gpu.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /* So far, with hardware that I've seen to date, we can have:
  25. * + zero, one, or two z180 2d cores
  26. * + a3xx or a2xx 3d core, which share a common CP (the firmware
  27. * for the CP seems to implement some different PM4 packet types
  28. * but the basics of cmdstream submission are the same)
  29. *
  30. * Which means that the eventual complete "class" hierarchy, once
  31. * support for all past and present hw is in place, becomes:
  32. * + msm_gpu
  33. * + adreno_gpu
  34. * + a3xx_gpu
  35. * + a2xx_gpu
  36. * + z180_gpu
  37. */
  38. struct msm_gpu_funcs {
  39. int (*get_param)(struct msm_gpu *gpu, uint32_t param, uint64_t *value);
  40. int (*hw_init)(struct msm_gpu *gpu);
  41. int (*pm_suspend)(struct msm_gpu *gpu);
  42. int (*pm_resume)(struct msm_gpu *gpu);
  43. int (*submit)(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  44. struct msm_file_private *ctx);
  45. void (*flush)(struct msm_gpu *gpu);
  46. void (*idle)(struct msm_gpu *gpu);
  47. irqreturn_t (*irq)(struct msm_gpu *irq);
  48. uint32_t (*last_fence)(struct msm_gpu *gpu);
  49. void (*recover)(struct msm_gpu *gpu);
  50. void (*destroy)(struct msm_gpu *gpu);
  51. #ifdef CONFIG_DEBUG_FS
  52. /* show GPU status in debugfs: */
  53. void (*show)(struct msm_gpu *gpu, struct seq_file *m);
  54. #endif
  55. };
  56. struct msm_gpu {
  57. const char *name;
  58. struct drm_device *dev;
  59. const struct msm_gpu_funcs *funcs;
  60. struct msm_ringbuffer *rb;
  61. uint32_t rb_iova;
  62. /* list of GEM active objects: */
  63. struct list_head active_list;
  64. uint32_t submitted_fence;
  65. /* worker for handling active-list retiring: */
  66. struct work_struct retire_work;
  67. void __iomem *mmio;
  68. int irq;
  69. struct iommu_domain *iommu;
  70. int id;
  71. /* Power Control: */
  72. struct regulator *gpu_reg, *gpu_cx;
  73. struct clk *ebi1_clk, *grp_clks[5];
  74. uint32_t fast_rate, slow_rate, bus_freq;
  75. uint32_t bsc;
  76. /* Hang Detction: */
  77. #define DRM_MSM_HANGCHECK_PERIOD 500 /* in ms */
  78. #define DRM_MSM_HANGCHECK_JIFFIES msecs_to_jiffies(DRM_MSM_HANGCHECK_PERIOD)
  79. struct timer_list hangcheck_timer;
  80. uint32_t hangcheck_fence;
  81. struct work_struct recover_work;
  82. };
  83. static inline void gpu_write(struct msm_gpu *gpu, u32 reg, u32 data)
  84. {
  85. msm_writel(data, gpu->mmio + (reg << 2));
  86. }
  87. static inline u32 gpu_read(struct msm_gpu *gpu, u32 reg)
  88. {
  89. return msm_readl(gpu->mmio + (reg << 2));
  90. }
  91. int msm_gpu_pm_suspend(struct msm_gpu *gpu);
  92. int msm_gpu_pm_resume(struct msm_gpu *gpu);
  93. void msm_gpu_retire(struct msm_gpu *gpu);
  94. int msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,
  95. struct msm_file_private *ctx);
  96. int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,
  97. struct msm_gpu *gpu, const struct msm_gpu_funcs *funcs,
  98. const char *name, const char *ioname, const char *irqname, int ringsz);
  99. void msm_gpu_cleanup(struct msm_gpu *gpu);
  100. struct msm_gpu *a3xx_gpu_init(struct drm_device *dev);
  101. void __init a3xx_register(void);
  102. void __exit a3xx_unregister(void);
  103. #endif /* __MSM_GPU_H__ */