Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

msm_priv.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (C) 2012-2018 Rob Clark <robclark@freedesktop.org>
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. * Authors:
  24. * Rob Clark <robclark@freedesktop.org>
  25. */
  26. #ifndef MSM_PRIV_H_
  27. #define MSM_PRIV_H_
  28. #include "freedreno_priv.h"
  29. #ifndef __user
  30. # define __user
  31. #endif
  32. #include "drm-uapi/msm_drm.h"
  33. struct msm_device {
  34. struct fd_device base;
  35. struct fd_bo_cache ring_cache;
  36. };
  37. FD_DEFINE_CAST(fd_device, msm_device);
  38. struct fd_device * msm_device_new(int fd);
  39. struct msm_pipe {
  40. struct fd_pipe base;
  41. uint32_t pipe;
  42. uint32_t gpu_id;
  43. uint64_t gmem_base;
  44. uint32_t gmem;
  45. uint32_t chip_id;
  46. uint32_t queue_id;
  47. };
  48. FD_DEFINE_CAST(fd_pipe, msm_pipe);
  49. struct fd_pipe * msm_pipe_new(struct fd_device *dev,
  50. enum fd_pipe_id id, uint32_t prio);
  51. struct fd_ringbuffer * msm_ringbuffer_new_object(struct fd_pipe *pipe, uint32_t size);
  52. struct fd_ringbuffer * msm_ringbuffer_sp_new_object(struct fd_pipe *pipe, uint32_t size);
  53. struct fd_submit * msm_submit_new(struct fd_pipe *pipe);
  54. struct fd_submit * msm_submit_sp_new(struct fd_pipe *pipe);
  55. struct msm_bo {
  56. struct fd_bo base;
  57. uint64_t offset;
  58. /* to avoid excess hashtable lookups, cache the ring this bo was
  59. * last emitted on (since that will probably also be the next ring
  60. * it is emitted on)
  61. */
  62. unsigned current_submit_seqno;
  63. uint32_t idx;
  64. };
  65. FD_DEFINE_CAST(fd_bo, msm_bo);
  66. int msm_bo_new_handle(struct fd_device *dev,
  67. uint32_t size, uint32_t flags, uint32_t *handle);
  68. struct fd_bo * msm_bo_from_handle(struct fd_device *dev,
  69. uint32_t size, uint32_t handle);
  70. static inline void
  71. msm_dump_submit(struct drm_msm_gem_submit *req)
  72. {
  73. for (unsigned i = 0; i < req->nr_bos; i++) {
  74. struct drm_msm_gem_submit_bo *bos = U642VOID(req->bos);
  75. struct drm_msm_gem_submit_bo *bo = &bos[i];
  76. ERROR_MSG(" bos[%d]: handle=%u, flags=%x", i, bo->handle, bo->flags);
  77. }
  78. for (unsigned i = 0; i < req->nr_cmds; i++) {
  79. struct drm_msm_gem_submit_cmd *cmds = U642VOID(req->cmds);
  80. struct drm_msm_gem_submit_cmd *cmd = &cmds[i];
  81. struct drm_msm_gem_submit_reloc *relocs = U642VOID(cmd->relocs);
  82. ERROR_MSG(" cmd[%d]: type=%u, submit_idx=%u, submit_offset=%u, size=%u",
  83. i, cmd->type, cmd->submit_idx, cmd->submit_offset, cmd->size);
  84. for (unsigned j = 0; j < cmd->nr_relocs; j++) {
  85. struct drm_msm_gem_submit_reloc *r = &relocs[j];
  86. ERROR_MSG(" reloc[%d]: submit_offset=%u, or=%08x, shift=%d, reloc_idx=%u"
  87. ", reloc_offset=%"PRIu64, j, r->submit_offset, r->or, r->shift,
  88. r->reloc_idx, (uint64_t)r->reloc_offset);
  89. }
  90. }
  91. }
  92. static inline void get_abs_timeout(struct drm_msm_timespec *tv, uint64_t ns)
  93. {
  94. struct timespec t;
  95. uint32_t s = ns / 1000000000;
  96. clock_gettime(CLOCK_MONOTONIC, &t);
  97. tv->tv_sec = t.tv_sec + s;
  98. tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000);
  99. }
  100. /*
  101. * Stupid/simple growable array implementation:
  102. */
  103. static inline void *
  104. grow(void *ptr, uint16_t nr, uint16_t *max, uint16_t sz)
  105. {
  106. if ((nr + 1) > *max) {
  107. if ((*max * 2) < (nr + 1))
  108. *max = nr + 5;
  109. else
  110. *max = *max * 2;
  111. ptr = realloc(ptr, *max * sz);
  112. }
  113. return ptr;
  114. }
  115. #define DECLARE_ARRAY(type, name) \
  116. unsigned short nr_ ## name, max_ ## name; \
  117. type * name;
  118. #define APPEND(x, name) ({ \
  119. (x)->name = grow((x)->name, (x)->nr_ ## name, &(x)->max_ ## name, sizeof((x)->name[0])); \
  120. (x)->nr_ ## name ++; \
  121. })
  122. #endif /* MSM_PRIV_H_ */