sde_rotator_util.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __SDE_ROTATOR_UTIL_H__
  6. #define __SDE_ROTATOR_UTIL_H__
  7. #include <linux/types.h>
  8. #include <linux/file.h>
  9. #include <linux/kref.h>
  10. #include <linux/kernel.h>
  11. #include <linux/device.h>
  12. #include <linux/dma-buf.h>
  13. #include "sde_rotator_hwio.h"
  14. #include "sde_rotator_base.h"
  15. #include "sde_rotator_sync.h"
  16. #include "sde_rotator_io_util.h"
  17. #include "sde_rotator_formats.h"
  18. #define SDE_ROT_MAX_IMG_WIDTH 0x3FFF
  19. #define SDE_ROT_MAX_IMG_HEIGHT 0x3FFF
  20. #define SDEROT_DBG(fmt, ...) pr_debug("<SDEROT_DBG> " fmt, ##__VA_ARGS__)
  21. #define SDEROT_INFO(fmt, ...) pr_info("<SDEROT_INFO> " fmt, ##__VA_ARGS__)
  22. #define SDEROT_INFO_ONCE(fmt, ...) \
  23. pr_info_once("<SDEROT_INFO> " fmt, ##__VA_ARGS__)
  24. #define SDEROT_WARN(fmt, ...) pr_warn("<SDEROT_WARN> " fmt, ##__VA_ARGS__)
  25. #define SDEROT_ERR(fmt, ...) pr_err("<SDEROT_ERR> " fmt, ##__VA_ARGS__)
  26. #define SDEDEV_DBG(dev, fmt, ...) \
  27. dev_dbg(dev, "<SDEROT_DBG> " fmt, ##__VA_ARGS__)
  28. #define SDEDEV_INFO(dev, fmt, ...) \
  29. dev_info(dev, "<SDEROT_INFO> " fmt, ##__VA_ARGS__)
  30. #define SDEDEV_WARN(dev, fmt, ...) \
  31. dev_warn(dev, "<SDEROT_WARN> " fmt, ##__VA_ARGS__)
  32. #define SDEDEV_ERR(dev, fmt, ...) \
  33. dev_err(dev, "<SDEROT_ERR> " fmt, ##__VA_ARGS__)
  34. #define PHY_ADDR_4G (1ULL<<32)
  35. struct sde_rect {
  36. u16 x;
  37. u16 y;
  38. u16 w;
  39. u16 h;
  40. };
  41. /* sde flag values */
  42. #define SDE_ROT_NOP 0
  43. #define SDE_FLIP_LR 0x1
  44. #define SDE_FLIP_UD 0x2
  45. #define SDE_ROT_90 0x4
  46. #define SDE_ROT_180 (SDE_FLIP_UD|SDE_FLIP_LR)
  47. #define SDE_ROT_270 (SDE_ROT_90|SDE_FLIP_UD|SDE_FLIP_LR)
  48. #define SDE_DEINTERLACE 0x80000000
  49. #define SDE_SOURCE_ROTATED_90 0x00100000
  50. #define SDE_SECURE_OVERLAY_SESSION 0x00008000
  51. #define SDE_ROT_EXT_DMA_BUF 0x00010000
  52. #define SDE_SECURE_CAMERA_SESSION 0x00020000
  53. #define SDE_ROT_EXT_IOVA 0x00040000
  54. struct sde_rot_data_type;
  55. struct sde_fb_data {
  56. uint32_t offset;
  57. struct dma_buf *buffer;
  58. int memory_id;
  59. int id;
  60. uint32_t flags;
  61. uint32_t priv;
  62. dma_addr_t addr;
  63. u32 len;
  64. };
  65. struct sde_layer_plane {
  66. /* DMA buffer file descriptor information. */
  67. int fd;
  68. struct dma_buf *buffer;
  69. /* i/o virtual address & length */
  70. dma_addr_t addr;
  71. u32 len;
  72. /* Pixel offset in the dma buffer. */
  73. uint32_t offset;
  74. /* Number of bytes in one scan line including padding bytes. */
  75. uint32_t stride;
  76. };
  77. struct sde_layer_buffer {
  78. /* layer width in pixels. */
  79. uint32_t width;
  80. /* layer height in pixels. */
  81. uint32_t height;
  82. /*
  83. * layer format in DRM-style fourcc, refer drm_fourcc.h for
  84. * standard formats
  85. */
  86. uint32_t format;
  87. /* plane to hold the fd, offset, etc for all color components */
  88. struct sde_layer_plane planes[SDE_ROT_MAX_PLANES];
  89. /* valid planes count in layer planes list */
  90. uint32_t plane_count;
  91. /* compression ratio factor, value depends on the pixel format */
  92. struct sde_mult_factor comp_ratio;
  93. /*
  94. * SyncFence associated with this buffer. It is used in two ways.
  95. *
  96. * 1. Driver waits to consume the buffer till producer signals in case
  97. * of primary and external display.
  98. *
  99. * 2. Writeback device uses buffer structure for output buffer where
  100. * driver is producer. However, client sends the fence with buffer to
  101. * indicate that consumer is still using the buffer and it is not ready
  102. * for new content.
  103. */
  104. struct sde_rot_sync_fence *fence;
  105. /* indicate if this is a stream (inline) buffer */
  106. bool sbuf;
  107. /* specify the system cache id in stream buffer mode */
  108. int scid;
  109. /* indicate if system cache writeback is required */
  110. bool writeback;
  111. };
  112. struct sde_mdp_plane_sizes {
  113. u32 num_planes;
  114. u32 plane_size[SDE_ROT_MAX_PLANES];
  115. u32 total_size;
  116. u32 ystride[SDE_ROT_MAX_PLANES];
  117. u32 rau_cnt;
  118. u32 rau_h[2];
  119. };
  120. struct sde_mdp_img_data {
  121. dma_addr_t addr;
  122. unsigned long len;
  123. u32 offset;
  124. u32 flags;
  125. bool mapped;
  126. bool skip_detach;
  127. struct fd srcp_f;
  128. struct dma_buf *srcp_dma_buf;
  129. struct dma_buf_attachment *srcp_attachment;
  130. struct sg_table *srcp_table;
  131. };
  132. struct sde_mdp_data {
  133. u8 num_planes;
  134. struct sde_mdp_img_data p[SDE_ROT_MAX_PLANES];
  135. bool sbuf;
  136. int scid;
  137. bool writeback;
  138. };
  139. void sde_mdp_get_v_h_subsample_rate(u8 chroma_sample,
  140. u8 *v_sample, u8 *h_sample);
  141. static inline u32 sde_mdp_general_align(u32 data, u32 alignment)
  142. {
  143. return ((data + alignment - 1)/alignment) * alignment;
  144. }
  145. void sde_rot_data_calc_offset(struct sde_mdp_data *data, u16 x, u16 y,
  146. struct sde_mdp_plane_sizes *ps, struct sde_mdp_format_params *fmt);
  147. int sde_validate_offset_for_ubwc_format(
  148. struct sde_mdp_format_params *fmt, u16 x, u16 y);
  149. int sde_mdp_data_get_and_validate_size(struct sde_mdp_data *data,
  150. struct sde_fb_data *planes, int num_planes, u32 flags,
  151. struct device *dev, bool rotator, int dir,
  152. struct sde_layer_buffer *buffer);
  153. int sde_mdp_get_plane_sizes(struct sde_mdp_format_params *fmt, u32 w, u32 h,
  154. struct sde_mdp_plane_sizes *ps, u32 bwc_mode,
  155. bool rotation);
  156. int sde_mdp_data_map(struct sde_mdp_data *data, bool rotator, int dir);
  157. int sde_mdp_data_check(struct sde_mdp_data *data,
  158. struct sde_mdp_plane_sizes *ps,
  159. struct sde_mdp_format_params *fmt);
  160. void sde_mdp_data_free(struct sde_mdp_data *data, bool rotator, int dir);
  161. struct dma_buf *sde_rot_get_dmabuf(struct sde_mdp_img_data *data);
  162. #endif /* __SDE_ROTATOR_UTIL_H__ */