sde_formats.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2015-2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SDE_FORMATS_H
  6. #define _SDE_FORMATS_H
  7. #include <drm/drm_fourcc.h>
  8. #include "msm_gem.h"
  9. #include "sde_hw_mdss.h"
  10. /**
  11. * sde_get_sde_format_ext() - Returns sde format structure pointer.
  12. * @format: DRM FourCC Code
  13. * @modifier: format modifier from client
  14. */
  15. const struct sde_format *sde_get_sde_format_ext(
  16. const uint32_t format,
  17. const uint64_t modifier);
  18. #define sde_get_sde_format(f) sde_get_sde_format_ext(f, 0)
  19. /**
  20. * sde_get_msm_format - get an sde_format by its msm_format base
  21. * callback function registers with the msm_kms layer
  22. * @kms: kms driver
  23. * @format: DRM FourCC Code
  24. * @modifier: data layout modifier
  25. */
  26. const struct msm_format *sde_get_msm_format(
  27. struct msm_kms *kms,
  28. const uint32_t format,
  29. const uint64_t modifier);
  30. /**
  31. * sde_populate_formats - populate the given array with fourcc codes supported
  32. * @format_list: pointer to list of possible formats
  33. * @pixel_formats: array to populate with fourcc codes
  34. * @pixel_modifiers: array to populate with drm modifiers, can be NULL
  35. * @pixel_formats_max: length of pixel formats array
  36. * Return: number of elements populated
  37. */
  38. uint32_t sde_populate_formats(
  39. const struct sde_format_extended *format_list,
  40. uint32_t *pixel_formats,
  41. uint64_t *pixel_modifiers,
  42. uint32_t pixel_formats_max);
  43. /**
  44. * sde_format_get_plane_sizes - calculate size and layout of given buffer format
  45. * @fmt: pointer to sde_format
  46. * @w: width of the buffer
  47. * @h: height of the buffer
  48. * @layout: layout of the buffer
  49. * @pitches: array of size [SDE_MAX_PLANES] to populate
  50. * pitch for each plane
  51. *
  52. * Return: size of the buffer
  53. */
  54. int sde_format_get_plane_sizes(
  55. const struct sde_format *fmt,
  56. const uint32_t w,
  57. const uint32_t h,
  58. struct sde_hw_fmt_layout *layout,
  59. const uint32_t *pitches);
  60. /**
  61. * sde_format_get_block_size - get block size of given format when
  62. * operating in block mode
  63. * @fmt: pointer to sde_format
  64. * @w: pointer to width of the block
  65. * @h: pointer to height of the block
  66. *
  67. * Return: 0 if success; error oode otherwise
  68. */
  69. int sde_format_get_block_size(const struct sde_format *fmt,
  70. uint32_t *w, uint32_t *h);
  71. /**
  72. * sde_format_check_modified_format - validate format and buffers for
  73. * sde non-standard, i.e. modified format
  74. * @kms: kms driver
  75. * @msm_fmt: pointer to the msm_fmt base pointer of an sde_format
  76. * @cmd: fb_cmd2 structure user request
  77. * @bos: gem buffer object list
  78. *
  79. * Return: error code on failure, 0 on success
  80. */
  81. int sde_format_check_modified_format(
  82. const struct msm_kms *kms,
  83. const struct msm_format *msm_fmt,
  84. const struct drm_mode_fb_cmd2 *cmd,
  85. struct drm_gem_object **bos);
  86. /**
  87. * sde_format_populate_layout - populate the given format layout based on
  88. * mmu, fb, and format found in the fb
  89. * @aspace: address space pointer
  90. * @fb: framebuffer pointer
  91. * @fmtl: format layout structure to populate
  92. *
  93. * Return: error code on failure, -EAGAIN if success but the addresses
  94. * are the same as before or 0 if new addresses were populated
  95. */
  96. int sde_format_populate_layout(
  97. struct msm_gem_address_space *aspace,
  98. struct drm_framebuffer *fb,
  99. struct sde_hw_fmt_layout *fmtl);
  100. /**
  101. * sde_format_populate_layout_with_roi - populate the given format layout
  102. * based on mmu, fb, roi, and format found in the fb
  103. * @aspace: address space pointer
  104. * @fb: framebuffer pointer
  105. * @roi: region of interest (optional)
  106. * @fmtl: format layout structure to populate
  107. *
  108. * Return: error code on failure, 0 on success
  109. */
  110. int sde_format_populate_layout_with_roi(
  111. struct msm_gem_address_space *aspace,
  112. struct drm_framebuffer *fb,
  113. struct sde_rect *roi,
  114. struct sde_hw_fmt_layout *fmtl);
  115. /**
  116. * sde_format_get_framebuffer_size - get framebuffer memory size
  117. * @format: DRM pixel format
  118. * @width: pixel width
  119. * @height: pixel height
  120. * @pitches: array of size [SDE_MAX_PLANES] to populate
  121. * pitch for each plane
  122. * @modifier: drm modifier
  123. *
  124. * Return: memory size required for frame buffer
  125. */
  126. uint32_t sde_format_get_framebuffer_size(
  127. const uint32_t format,
  128. const uint32_t width,
  129. const uint32_t height,
  130. const uint32_t *pitches,
  131. const uint64_t modifier);
  132. /**
  133. * sde_format_is_tp10_ubwc - check if the format is tp10 ubwc
  134. * @format: DRM pixel format
  135. *
  136. * Return: returns true if the format is tp10 ubwc, otherwise false.
  137. */
  138. bool sde_format_is_tp10_ubwc(const struct sde_format *fmt);
  139. /**
  140. * sde_format_validate_fmt - validates if the format "sde_fmt" is within
  141. * the list "fmt_list"
  142. * @kms: pointer to the kms object
  143. * @sde_fmt: pointer to the format to look within the list
  144. * @fmt_list: list where driver will loop to look for the 'sde_fmt' format.
  145. * @result: returns 0 if the format is found, otherwise will return an
  146. * error code.
  147. */
  148. int sde_format_validate_fmt(struct msm_kms *kms,
  149. const struct sde_format *sde_fmt,
  150. const struct sde_format_extended *fmt_list);
  151. #endif /*_SDE_FORMATS_H */