lima_drm.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
  2. /* Copyright 2017-2018 Qiang Yu <yuq825@gmail.com> */
  3. #ifndef __LIMA_DRM_H__
  4. #define __LIMA_DRM_H__
  5. #include "drm.h"
  6. #if defined(__cplusplus)
  7. extern "C" {
  8. #endif
  9. enum drm_lima_param_gpu_id {
  10. DRM_LIMA_PARAM_GPU_ID_UNKNOWN,
  11. DRM_LIMA_PARAM_GPU_ID_MALI400,
  12. DRM_LIMA_PARAM_GPU_ID_MALI450,
  13. };
  14. enum drm_lima_param {
  15. DRM_LIMA_PARAM_GPU_ID,
  16. DRM_LIMA_PARAM_NUM_PP,
  17. DRM_LIMA_PARAM_GP_VERSION,
  18. DRM_LIMA_PARAM_PP_VERSION,
  19. };
  20. /**
  21. * get various information of the GPU
  22. */
  23. struct drm_lima_get_param {
  24. __u32 param; /* in, value in enum drm_lima_param */
  25. __u32 pad; /* pad, must be zero */
  26. __u64 value; /* out, parameter value */
  27. };
  28. /*
  29. * heap buffer dynamically increase backup memory size when GP task fail
  30. * due to lack of heap memory. size field of heap buffer is an up bound of
  31. * the backup memory which can be set to a fairly large value.
  32. */
  33. #define LIMA_BO_FLAG_HEAP (1 << 0)
  34. /**
  35. * create a buffer for used by GPU
  36. */
  37. struct drm_lima_gem_create {
  38. __u32 size; /* in, buffer size */
  39. __u32 flags; /* in, buffer flags */
  40. __u32 handle; /* out, GEM buffer handle */
  41. __u32 pad; /* pad, must be zero */
  42. };
  43. /**
  44. * get information of a buffer
  45. */
  46. struct drm_lima_gem_info {
  47. __u32 handle; /* in, GEM buffer handle */
  48. __u32 va; /* out, virtual address mapped into GPU MMU */
  49. __u64 offset; /* out, used to mmap this buffer to CPU */
  50. };
  51. #define LIMA_SUBMIT_BO_READ 0x01
  52. #define LIMA_SUBMIT_BO_WRITE 0x02
  53. /* buffer information used by one task */
  54. struct drm_lima_gem_submit_bo {
  55. __u32 handle; /* in, GEM buffer handle */
  56. __u32 flags; /* in, buffer read/write by GPU */
  57. };
  58. #define LIMA_GP_FRAME_REG_NUM 6
  59. /* frame used to setup GP for each task */
  60. struct drm_lima_gp_frame {
  61. __u32 frame[LIMA_GP_FRAME_REG_NUM];
  62. };
  63. #define LIMA_PP_FRAME_REG_NUM 23
  64. #define LIMA_PP_WB_REG_NUM 12
  65. /* frame used to setup mali400 GPU PP for each task */
  66. struct drm_lima_m400_pp_frame {
  67. __u32 frame[LIMA_PP_FRAME_REG_NUM];
  68. __u32 num_pp;
  69. __u32 wb[3 * LIMA_PP_WB_REG_NUM];
  70. __u32 plbu_array_address[4];
  71. __u32 fragment_stack_address[4];
  72. };
  73. /* frame used to setup mali450 GPU PP for each task */
  74. struct drm_lima_m450_pp_frame {
  75. __u32 frame[LIMA_PP_FRAME_REG_NUM];
  76. __u32 num_pp;
  77. __u32 wb[3 * LIMA_PP_WB_REG_NUM];
  78. __u32 use_dlbu;
  79. __u32 _pad;
  80. union {
  81. __u32 plbu_array_address[8];
  82. __u32 dlbu_regs[4];
  83. };
  84. __u32 fragment_stack_address[8];
  85. };
  86. #define LIMA_PIPE_GP 0x00
  87. #define LIMA_PIPE_PP 0x01
  88. #define LIMA_SUBMIT_FLAG_EXPLICIT_FENCE (1 << 0)
  89. /**
  90. * submit a task to GPU
  91. *
  92. * User can always merge multi sync_file and drm_syncobj
  93. * into one drm_syncobj as in_sync[0], but we reserve
  94. * in_sync[1] for another task's out_sync to avoid the
  95. * export/import/merge pass when explicit sync.
  96. */
  97. struct drm_lima_gem_submit {
  98. __u32 ctx; /* in, context handle task is submitted to */
  99. __u32 pipe; /* in, which pipe to use, GP/PP */
  100. __u32 nr_bos; /* in, array length of bos field */
  101. __u32 frame_size; /* in, size of frame field */
  102. __u64 bos; /* in, array of drm_lima_gem_submit_bo */
  103. __u64 frame; /* in, GP/PP frame */
  104. __u32 flags; /* in, submit flags */
  105. __u32 out_sync; /* in, drm_syncobj handle used to wait task finish after submission */
  106. __u32 in_sync[2]; /* in, drm_syncobj handle used to wait before start this task */
  107. };
  108. #define LIMA_GEM_WAIT_READ 0x01
  109. #define LIMA_GEM_WAIT_WRITE 0x02
  110. /**
  111. * wait pending GPU task finish of a buffer
  112. */
  113. struct drm_lima_gem_wait {
  114. __u32 handle; /* in, GEM buffer handle */
  115. __u32 op; /* in, CPU want to read/write this buffer */
  116. __s64 timeout_ns; /* in, wait timeout in absulute time */
  117. };
  118. /**
  119. * create a context
  120. */
  121. struct drm_lima_ctx_create {
  122. __u32 id; /* out, context handle */
  123. __u32 _pad; /* pad, must be zero */
  124. };
  125. /**
  126. * free a context
  127. */
  128. struct drm_lima_ctx_free {
  129. __u32 id; /* in, context handle */
  130. __u32 _pad; /* pad, must be zero */
  131. };
  132. #define DRM_LIMA_GET_PARAM 0x00
  133. #define DRM_LIMA_GEM_CREATE 0x01
  134. #define DRM_LIMA_GEM_INFO 0x02
  135. #define DRM_LIMA_GEM_SUBMIT 0x03
  136. #define DRM_LIMA_GEM_WAIT 0x04
  137. #define DRM_LIMA_CTX_CREATE 0x05
  138. #define DRM_LIMA_CTX_FREE 0x06
  139. #define DRM_IOCTL_LIMA_GET_PARAM DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GET_PARAM, struct drm_lima_get_param)
  140. #define DRM_IOCTL_LIMA_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GEM_CREATE, struct drm_lima_gem_create)
  141. #define DRM_IOCTL_LIMA_GEM_INFO DRM_IOWR(DRM_COMMAND_BASE + DRM_LIMA_GEM_INFO, struct drm_lima_gem_info)
  142. #define DRM_IOCTL_LIMA_GEM_SUBMIT DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_GEM_SUBMIT, struct drm_lima_gem_submit)
  143. #define DRM_IOCTL_LIMA_GEM_WAIT DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_GEM_WAIT, struct drm_lima_gem_wait)
  144. #define DRM_IOCTL_LIMA_CTX_CREATE DRM_IOR(DRM_COMMAND_BASE + DRM_LIMA_CTX_CREATE, struct drm_lima_ctx_create)
  145. #define DRM_IOCTL_LIMA_CTX_FREE DRM_IOW(DRM_COMMAND_BASE + DRM_LIMA_CTX_FREE, struct drm_lima_ctx_free)
  146. #if defined(__cplusplus)
  147. }
  148. #endif
  149. #endif /* __LIMA_DRM_H__ */