msm_drv.h 7.1 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_DRV_H__
  18. #define __MSM_DRV_H__
  19. #include <linux/kernel.h>
  20. #include <linux/clk.h>
  21. #include <linux/cpufreq.h>
  22. #include <linux/module.h>
  23. #include <linux/platform_device.h>
  24. #include <linux/pm.h>
  25. #include <linux/pm_runtime.h>
  26. #include <linux/slab.h>
  27. #include <linux/list.h>
  28. #include <linux/iommu.h>
  29. #include <linux/types.h>
  30. #include <asm/sizes.h>
  31. #ifndef CONFIG_OF
  32. #include <mach/board.h>
  33. #include <mach/socinfo.h>
  34. #include <mach/iommu_domains.h>
  35. #endif
  36. #include <drm/drmP.h>
  37. #include <drm/drm_crtc_helper.h>
  38. #include <drm/drm_fb_helper.h>
  39. #include <drm/msm_drm.h>
  40. struct msm_kms;
  41. struct msm_gpu;
  42. #define NUM_DOMAINS 2 /* one for KMS, then one per gpu core (?) */
  43. struct msm_file_private {
  44. /* currently we don't do anything useful with this.. but when
  45. * per-context address spaces are supported we'd keep track of
  46. * the context's page-tables here.
  47. */
  48. int dummy;
  49. };
  50. struct msm_drm_private {
  51. struct msm_kms *kms;
  52. /* when we have more than one 'msm_gpu' these need to be an array: */
  53. struct msm_gpu *gpu;
  54. struct msm_file_private *lastctx;
  55. struct drm_fb_helper *fbdev;
  56. uint32_t next_fence, completed_fence;
  57. wait_queue_head_t fence_event;
  58. /* list of GEM objects: */
  59. struct list_head inactive_list;
  60. struct workqueue_struct *wq;
  61. /* registered IOMMU domains: */
  62. unsigned int num_iommus;
  63. struct iommu_domain *iommus[NUM_DOMAINS];
  64. unsigned int num_crtcs;
  65. struct drm_crtc *crtcs[8];
  66. unsigned int num_encoders;
  67. struct drm_encoder *encoders[8];
  68. unsigned int num_bridges;
  69. struct drm_bridge *bridges[8];
  70. unsigned int num_connectors;
  71. struct drm_connector *connectors[8];
  72. };
  73. struct msm_format {
  74. uint32_t pixel_format;
  75. };
  76. /* As there are different display controller blocks depending on the
  77. * snapdragon version, the kms support is split out and the appropriate
  78. * implementation is loaded at runtime. The kms module is responsible
  79. * for constructing the appropriate planes/crtcs/encoders/connectors.
  80. */
  81. struct msm_kms_funcs {
  82. /* hw initialization: */
  83. int (*hw_init)(struct msm_kms *kms);
  84. /* irq handling: */
  85. void (*irq_preinstall)(struct msm_kms *kms);
  86. int (*irq_postinstall)(struct msm_kms *kms);
  87. void (*irq_uninstall)(struct msm_kms *kms);
  88. irqreturn_t (*irq)(struct msm_kms *kms);
  89. int (*enable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  90. void (*disable_vblank)(struct msm_kms *kms, struct drm_crtc *crtc);
  91. /* misc: */
  92. const struct msm_format *(*get_format)(struct msm_kms *kms, uint32_t format);
  93. long (*round_pixclk)(struct msm_kms *kms, unsigned long rate,
  94. struct drm_encoder *encoder);
  95. /* cleanup: */
  96. void (*preclose)(struct msm_kms *kms, struct drm_file *file);
  97. void (*destroy)(struct msm_kms *kms);
  98. };
  99. struct msm_kms {
  100. const struct msm_kms_funcs *funcs;
  101. };
  102. struct msm_kms *mdp4_kms_init(struct drm_device *dev);
  103. int msm_register_iommu(struct drm_device *dev, struct iommu_domain *iommu);
  104. int msm_iommu_attach(struct drm_device *dev, struct iommu_domain *iommu,
  105. const char **names, int cnt);
  106. int msm_wait_fence_interruptable(struct drm_device *dev, uint32_t fence,
  107. struct timespec *timeout);
  108. void msm_update_fence(struct drm_device *dev, uint32_t fence);
  109. int msm_ioctl_gem_submit(struct drm_device *dev, void *data,
  110. struct drm_file *file);
  111. int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  112. int msm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  113. uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);
  114. int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,
  115. uint32_t *iova);
  116. int msm_gem_get_iova(struct drm_gem_object *obj, int id, uint32_t *iova);
  117. void msm_gem_put_iova(struct drm_gem_object *obj, int id);
  118. int msm_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  119. struct drm_mode_create_dumb *args);
  120. int msm_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
  121. uint32_t handle);
  122. int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
  123. uint32_t handle, uint64_t *offset);
  124. void *msm_gem_vaddr_locked(struct drm_gem_object *obj);
  125. void *msm_gem_vaddr(struct drm_gem_object *obj);
  126. int msm_gem_queue_inactive_work(struct drm_gem_object *obj,
  127. struct work_struct *work);
  128. void msm_gem_move_to_active(struct drm_gem_object *obj,
  129. struct msm_gpu *gpu, bool write, uint32_t fence);
  130. void msm_gem_move_to_inactive(struct drm_gem_object *obj);
  131. int msm_gem_cpu_prep(struct drm_gem_object *obj, uint32_t op,
  132. struct timespec *timeout);
  133. int msm_gem_cpu_fini(struct drm_gem_object *obj);
  134. void msm_gem_free_object(struct drm_gem_object *obj);
  135. int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,
  136. uint32_t size, uint32_t flags, uint32_t *handle);
  137. struct drm_gem_object *msm_gem_new(struct drm_device *dev,
  138. uint32_t size, uint32_t flags);
  139. struct drm_gem_object *msm_framebuffer_bo(struct drm_framebuffer *fb, int plane);
  140. const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb);
  141. struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev,
  142. struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos);
  143. struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev,
  144. struct drm_file *file, struct drm_mode_fb_cmd2 *mode_cmd);
  145. struct drm_fb_helper *msm_fbdev_init(struct drm_device *dev);
  146. int hdmi_init(struct drm_device *dev, struct drm_encoder *encoder);
  147. void __init hdmi_register(void);
  148. void __exit hdmi_unregister(void);
  149. #ifdef CONFIG_DEBUG_FS
  150. void msm_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
  151. void msm_gem_describe_objects(struct list_head *list, struct seq_file *m);
  152. void msm_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
  153. #endif
  154. void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
  155. const char *dbgname);
  156. void msm_writel(u32 data, void __iomem *addr);
  157. u32 msm_readl(const void __iomem *addr);
  158. #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  159. #define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  160. static inline bool fence_completed(struct drm_device *dev, uint32_t fence)
  161. {
  162. struct msm_drm_private *priv = dev->dev_private;
  163. return priv->completed_fence >= fence;
  164. }
  165. static inline int align_pitch(int width, int bpp)
  166. {
  167. int bytespp = (bpp + 7) / 8;
  168. /* adreno needs pitch aligned to 32 pixels: */
  169. return bytespp * ALIGN(width, 32);
  170. }
  171. /* for the generated headers: */
  172. #define INVALID_IDX(idx) ({BUG(); 0;})
  173. #define fui(x) ({BUG(); 0;})
  174. #define util_float_to_half(x) ({BUG(); 0;})
  175. #define FIELD(val, name) (((val) & name ## __MASK) >> name ## __SHIFT)
  176. /* for conditionally setting boolean flag(s): */
  177. #define COND(bool, val) ((bool) ? (val) : 0)
  178. #endif /* __MSM_DRV_H__ */