omap_drv.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /*
  2. * drivers/gpu/drm/omapdrm/omap_drv.h
  3. *
  4. * Copyright (C) 2011 Texas Instruments
  5. * Author: Rob Clark <rob@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef __OMAP_DRV_H__
  20. #define __OMAP_DRV_H__
  21. #include <video/omapdss.h>
  22. #include <linux/module.h>
  23. #include <linux/types.h>
  24. #include <drm/drmP.h>
  25. #include <drm/drm_crtc_helper.h>
  26. #include <drm/omap_drm.h>
  27. #include <linux/platform_data/omap_drm.h>
  28. #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
  29. #define VERB(fmt, ...) if (0) DRM_DEBUG(fmt, ##__VA_ARGS__) /* verbose debug */
  30. #define MODULE_NAME "omapdrm"
  31. /* max # of mapper-id's that can be assigned.. todo, come up with a better
  32. * (but still inexpensive) way to store/access per-buffer mapper private
  33. * data..
  34. */
  35. #define MAX_MAPPERS 2
  36. /* parameters which describe (unrotated) coordinates of scanout within a fb: */
  37. struct omap_drm_window {
  38. uint32_t rotation;
  39. int32_t crtc_x, crtc_y; /* signed because can be offscreen */
  40. uint32_t crtc_w, crtc_h;
  41. uint32_t src_x, src_y;
  42. uint32_t src_w, src_h;
  43. };
  44. /* Once GO bit is set, we can't make further updates to shadowed registers
  45. * until the GO bit is cleared. So various parts in the kms code that need
  46. * to update shadowed registers queue up a pair of callbacks, pre_apply
  47. * which is called before setting GO bit, and post_apply that is called
  48. * after GO bit is cleared. The crtc manages the queuing, and everyone
  49. * else goes thru omap_crtc_apply() using these callbacks so that the
  50. * code which has to deal w/ GO bit state is centralized.
  51. */
  52. struct omap_drm_apply {
  53. struct list_head pending_node, queued_node;
  54. bool queued;
  55. void (*pre_apply)(struct omap_drm_apply *apply);
  56. void (*post_apply)(struct omap_drm_apply *apply);
  57. };
  58. /* For transiently registering for different DSS irqs that various parts
  59. * of the KMS code need during setup/configuration. We these are not
  60. * necessarily the same as what drm_vblank_get/put() are requesting, and
  61. * the hysteresis in drm_vblank_put() is not necessarily desirable for
  62. * internal housekeeping related irq usage.
  63. */
  64. struct omap_drm_irq {
  65. struct list_head node;
  66. uint32_t irqmask;
  67. bool registered;
  68. void (*irq)(struct omap_drm_irq *irq, uint32_t irqstatus);
  69. };
  70. /* For KMS code that needs to wait for a certain # of IRQs:
  71. */
  72. struct omap_irq_wait;
  73. struct omap_irq_wait * omap_irq_wait_init(struct drm_device *dev,
  74. uint32_t irqmask, int count);
  75. int omap_irq_wait(struct drm_device *dev, struct omap_irq_wait *wait,
  76. unsigned long timeout);
  77. struct omap_drm_private {
  78. uint32_t omaprev;
  79. unsigned int num_crtcs;
  80. struct drm_crtc *crtcs[8];
  81. unsigned int num_planes;
  82. struct drm_plane *planes[8];
  83. unsigned int num_encoders;
  84. struct drm_encoder *encoders[8];
  85. unsigned int num_connectors;
  86. struct drm_connector *connectors[8];
  87. struct drm_fb_helper *fbdev;
  88. struct workqueue_struct *wq;
  89. /* list of GEM objects: */
  90. struct list_head obj_list;
  91. bool has_dmm;
  92. /* properties: */
  93. struct drm_property *rotation_prop;
  94. struct drm_property *zorder_prop;
  95. /* irq handling: */
  96. struct list_head irq_list; /* list of omap_drm_irq */
  97. uint32_t vblank_mask; /* irq bits set for userspace vblank */
  98. struct omap_drm_irq error_handler;
  99. };
  100. /* this should probably be in drm-core to standardize amongst drivers */
  101. #define DRM_ROTATE_0 0
  102. #define DRM_ROTATE_90 1
  103. #define DRM_ROTATE_180 2
  104. #define DRM_ROTATE_270 3
  105. #define DRM_REFLECT_X 4
  106. #define DRM_REFLECT_Y 5
  107. #ifdef CONFIG_DEBUG_FS
  108. int omap_debugfs_init(struct drm_minor *minor);
  109. void omap_debugfs_cleanup(struct drm_minor *minor);
  110. void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
  111. void omap_gem_describe(struct drm_gem_object *obj, struct seq_file *m);
  112. void omap_gem_describe_objects(struct list_head *list, struct seq_file *m);
  113. #endif
  114. #ifdef CONFIG_PM
  115. int omap_gem_resume(struct device *dev);
  116. #endif
  117. int omap_irq_enable_vblank(struct drm_device *dev, int crtc_id);
  118. void omap_irq_disable_vblank(struct drm_device *dev, int crtc_id);
  119. irqreturn_t omap_irq_handler(DRM_IRQ_ARGS);
  120. void omap_irq_preinstall(struct drm_device *dev);
  121. int omap_irq_postinstall(struct drm_device *dev);
  122. void omap_irq_uninstall(struct drm_device *dev);
  123. void omap_irq_register(struct drm_device *dev, struct omap_drm_irq *irq);
  124. void omap_irq_unregister(struct drm_device *dev, struct omap_drm_irq *irq);
  125. int omap_drm_irq_uninstall(struct drm_device *dev);
  126. int omap_drm_irq_install(struct drm_device *dev);
  127. struct drm_fb_helper *omap_fbdev_init(struct drm_device *dev);
  128. void omap_fbdev_free(struct drm_device *dev);
  129. const struct omap_video_timings *omap_crtc_timings(struct drm_crtc *crtc);
  130. enum omap_channel omap_crtc_channel(struct drm_crtc *crtc);
  131. int omap_crtc_apply(struct drm_crtc *crtc,
  132. struct omap_drm_apply *apply);
  133. struct drm_crtc *omap_crtc_init(struct drm_device *dev,
  134. struct drm_plane *plane, enum omap_channel channel, int id);
  135. struct drm_plane *omap_plane_init(struct drm_device *dev,
  136. int plane_id, bool private_plane);
  137. int omap_plane_dpms(struct drm_plane *plane, int mode);
  138. int omap_plane_mode_set(struct drm_plane *plane,
  139. struct drm_crtc *crtc, struct drm_framebuffer *fb,
  140. int crtc_x, int crtc_y,
  141. unsigned int crtc_w, unsigned int crtc_h,
  142. uint32_t src_x, uint32_t src_y,
  143. uint32_t src_w, uint32_t src_h,
  144. void (*fxn)(void *), void *arg);
  145. void omap_plane_install_properties(struct drm_plane *plane,
  146. struct drm_mode_object *obj);
  147. int omap_plane_set_property(struct drm_plane *plane,
  148. struct drm_property *property, uint64_t val);
  149. struct drm_encoder *omap_encoder_init(struct drm_device *dev,
  150. struct omap_dss_device *dssdev);
  151. int omap_encoder_set_enabled(struct drm_encoder *encoder, bool enabled);
  152. int omap_encoder_update(struct drm_encoder *encoder,
  153. struct omap_overlay_manager *mgr,
  154. struct omap_video_timings *timings);
  155. struct drm_connector *omap_connector_init(struct drm_device *dev,
  156. int connector_type, struct omap_dss_device *dssdev,
  157. struct drm_encoder *encoder);
  158. struct drm_encoder *omap_connector_attached_encoder(
  159. struct drm_connector *connector);
  160. void omap_connector_flush(struct drm_connector *connector,
  161. int x, int y, int w, int h);
  162. void copy_timings_omap_to_drm(struct drm_display_mode *mode,
  163. struct omap_video_timings *timings);
  164. void copy_timings_drm_to_omap(struct omap_video_timings *timings,
  165. struct drm_display_mode *mode);
  166. uint32_t omap_framebuffer_get_formats(uint32_t *pixel_formats,
  167. uint32_t max_formats, enum omap_color_mode supported_modes);
  168. struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev,
  169. struct drm_file *file, struct drm_mode_fb_cmd2 *mode_cmd);
  170. struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
  171. struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos);
  172. struct drm_gem_object *omap_framebuffer_bo(struct drm_framebuffer *fb, int p);
  173. int omap_framebuffer_replace(struct drm_framebuffer *a,
  174. struct drm_framebuffer *b, void *arg,
  175. void (*unpin)(void *arg, struct drm_gem_object *bo));
  176. void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
  177. struct omap_drm_window *win, struct omap_overlay_info *info);
  178. struct drm_connector *omap_framebuffer_get_next_connector(
  179. struct drm_framebuffer *fb, struct drm_connector *from);
  180. void omap_framebuffer_flush(struct drm_framebuffer *fb,
  181. int x, int y, int w, int h);
  182. void omap_gem_init(struct drm_device *dev);
  183. void omap_gem_deinit(struct drm_device *dev);
  184. struct drm_gem_object *omap_gem_new(struct drm_device *dev,
  185. union omap_gem_size gsize, uint32_t flags);
  186. int omap_gem_new_handle(struct drm_device *dev, struct drm_file *file,
  187. union omap_gem_size gsize, uint32_t flags, uint32_t *handle);
  188. void omap_gem_free_object(struct drm_gem_object *obj);
  189. int omap_gem_init_object(struct drm_gem_object *obj);
  190. void *omap_gem_vaddr(struct drm_gem_object *obj);
  191. int omap_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,
  192. uint32_t handle, uint64_t *offset);
  193. int omap_gem_dumb_destroy(struct drm_file *file, struct drm_device *dev,
  194. uint32_t handle);
  195. int omap_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
  196. struct drm_mode_create_dumb *args);
  197. int omap_gem_mmap(struct file *filp, struct vm_area_struct *vma);
  198. int omap_gem_mmap_obj(struct drm_gem_object *obj,
  199. struct vm_area_struct *vma);
  200. int omap_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
  201. int omap_gem_op_start(struct drm_gem_object *obj, enum omap_gem_op op);
  202. int omap_gem_op_finish(struct drm_gem_object *obj, enum omap_gem_op op);
  203. int omap_gem_op_sync(struct drm_gem_object *obj, enum omap_gem_op op);
  204. int omap_gem_op_async(struct drm_gem_object *obj, enum omap_gem_op op,
  205. void (*fxn)(void *arg), void *arg);
  206. int omap_gem_roll(struct drm_gem_object *obj, uint32_t roll);
  207. void omap_gem_cpu_sync(struct drm_gem_object *obj, int pgoff);
  208. void omap_gem_dma_sync(struct drm_gem_object *obj,
  209. enum dma_data_direction dir);
  210. int omap_gem_get_paddr(struct drm_gem_object *obj,
  211. dma_addr_t *paddr, bool remap);
  212. int omap_gem_put_paddr(struct drm_gem_object *obj);
  213. int omap_gem_get_pages(struct drm_gem_object *obj, struct page ***pages,
  214. bool remap);
  215. int omap_gem_put_pages(struct drm_gem_object *obj);
  216. uint32_t omap_gem_flags(struct drm_gem_object *obj);
  217. int omap_gem_rotated_paddr(struct drm_gem_object *obj, uint32_t orient,
  218. int x, int y, dma_addr_t *paddr);
  219. uint64_t omap_gem_mmap_offset(struct drm_gem_object *obj);
  220. size_t omap_gem_mmap_size(struct drm_gem_object *obj);
  221. int omap_gem_tiled_size(struct drm_gem_object *obj, uint16_t *w, uint16_t *h);
  222. int omap_gem_tiled_stride(struct drm_gem_object *obj, uint32_t orient);
  223. struct dma_buf *omap_gem_prime_export(struct drm_device *dev,
  224. struct drm_gem_object *obj, int flags);
  225. struct drm_gem_object *omap_gem_prime_import(struct drm_device *dev,
  226. struct dma_buf *buffer);
  227. static inline int align_pitch(int pitch, int width, int bpp)
  228. {
  229. int bytespp = (bpp + 7) / 8;
  230. /* in case someone tries to feed us a completely bogus stride: */
  231. pitch = max(pitch, width * bytespp);
  232. /* PVR needs alignment to 8 pixels.. right now that is the most
  233. * restrictive stride requirement..
  234. */
  235. return ALIGN(pitch, 8 * bytespp);
  236. }
  237. /* map crtc to vblank mask */
  238. uint32_t pipe2vbl(struct drm_crtc *crtc);
  239. struct omap_dss_device *omap_encoder_get_dssdev(struct drm_encoder *encoder);
  240. /* should these be made into common util helpers?
  241. */
  242. static inline int objects_lookup(struct drm_device *dev,
  243. struct drm_file *filp, uint32_t pixel_format,
  244. struct drm_gem_object **bos, uint32_t *handles)
  245. {
  246. int i, n = drm_format_num_planes(pixel_format);
  247. for (i = 0; i < n; i++) {
  248. bos[i] = drm_gem_object_lookup(dev, filp, handles[i]);
  249. if (!bos[i])
  250. goto fail;
  251. }
  252. return 0;
  253. fail:
  254. while (--i > 0)
  255. drm_gem_object_unreference_unlocked(bos[i]);
  256. return -ENOENT;
  257. }
  258. #endif /* __OMAP_DRV_H__ */