tinydrm.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2016 Noralf Trønnes
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #ifndef __LINUX_TINYDRM_H
  10. #define __LINUX_TINYDRM_H
  11. #include <drm/drm_gem_cma_helper.h>
  12. #include <drm/drm_fb_cma_helper.h>
  13. #include <drm/drm_simple_kms_helper.h>
  14. /**
  15. * struct tinydrm_device - tinydrm device
  16. * @drm: DRM device
  17. * @pipe: Display pipe structure
  18. * @dirty_lock: Serializes framebuffer flushing
  19. * @fbdev_cma: CMA fbdev structure
  20. * @suspend_state: Atomic state when suspended
  21. * @fb_funcs: Framebuffer functions used when creating framebuffers
  22. */
  23. struct tinydrm_device {
  24. struct drm_device *drm;
  25. struct drm_simple_display_pipe pipe;
  26. struct mutex dirty_lock;
  27. struct drm_fbdev_cma *fbdev_cma;
  28. struct drm_atomic_state *suspend_state;
  29. const struct drm_framebuffer_funcs *fb_funcs;
  30. };
  31. static inline struct tinydrm_device *
  32. pipe_to_tinydrm(struct drm_simple_display_pipe *pipe)
  33. {
  34. return container_of(pipe, struct tinydrm_device, pipe);
  35. }
  36. /**
  37. * TINYDRM_GEM_DRIVER_OPS - default tinydrm gem operations
  38. *
  39. * This macro provides a shortcut for setting the tinydrm GEM operations in
  40. * the &drm_driver structure.
  41. */
  42. #define TINYDRM_GEM_DRIVER_OPS \
  43. .gem_free_object = tinydrm_gem_cma_free_object, \
  44. .gem_vm_ops = &drm_gem_cma_vm_ops, \
  45. .prime_handle_to_fd = drm_gem_prime_handle_to_fd, \
  46. .prime_fd_to_handle = drm_gem_prime_fd_to_handle, \
  47. .gem_prime_import = drm_gem_prime_import, \
  48. .gem_prime_export = drm_gem_prime_export, \
  49. .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, \
  50. .gem_prime_import_sg_table = tinydrm_gem_cma_prime_import_sg_table, \
  51. .gem_prime_vmap = drm_gem_cma_prime_vmap, \
  52. .gem_prime_vunmap = drm_gem_cma_prime_vunmap, \
  53. .gem_prime_mmap = drm_gem_cma_prime_mmap, \
  54. .dumb_create = drm_gem_cma_dumb_create
  55. /**
  56. * TINYDRM_MODE - tinydrm display mode
  57. * @hd: Horizontal resolution, width
  58. * @vd: Vertical resolution, height
  59. * @hd_mm: Display width in millimeters
  60. * @vd_mm: Display height in millimeters
  61. *
  62. * This macro creates a &drm_display_mode for use with tinydrm.
  63. */
  64. #define TINYDRM_MODE(hd, vd, hd_mm, vd_mm) \
  65. .hdisplay = (hd), \
  66. .hsync_start = (hd), \
  67. .hsync_end = (hd), \
  68. .htotal = (hd), \
  69. .vdisplay = (vd), \
  70. .vsync_start = (vd), \
  71. .vsync_end = (vd), \
  72. .vtotal = (vd), \
  73. .width_mm = (hd_mm), \
  74. .height_mm = (vd_mm), \
  75. .type = DRM_MODE_TYPE_DRIVER, \
  76. .clock = 1 /* pass validation */
  77. void tinydrm_lastclose(struct drm_device *drm);
  78. void tinydrm_gem_cma_free_object(struct drm_gem_object *gem_obj);
  79. struct drm_gem_object *
  80. tinydrm_gem_cma_prime_import_sg_table(struct drm_device *drm,
  81. struct dma_buf_attachment *attach,
  82. struct sg_table *sgt);
  83. int devm_tinydrm_init(struct device *parent, struct tinydrm_device *tdev,
  84. const struct drm_framebuffer_funcs *fb_funcs,
  85. struct drm_driver *driver);
  86. int devm_tinydrm_register(struct tinydrm_device *tdev);
  87. void tinydrm_shutdown(struct tinydrm_device *tdev);
  88. int tinydrm_suspend(struct tinydrm_device *tdev);
  89. int tinydrm_resume(struct tinydrm_device *tdev);
  90. void tinydrm_display_pipe_update(struct drm_simple_display_pipe *pipe,
  91. struct drm_plane_state *old_state);
  92. int tinydrm_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
  93. struct drm_plane_state *plane_state);
  94. int
  95. tinydrm_display_pipe_init(struct tinydrm_device *tdev,
  96. const struct drm_simple_display_pipe_funcs *funcs,
  97. int connector_type,
  98. const uint32_t *formats,
  99. unsigned int format_count,
  100. const struct drm_display_mode *mode,
  101. unsigned int rotation);
  102. #endif /* __LINUX_TINYDRM_H */