etnaviv_priv.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /*
  2. * Copyright (C) 2014-2015 Etnaviv Project
  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. * Christian Gmeiner <christian.gmeiner@gmail.com>
  25. */
  26. #ifndef ETNAVIV_PRIV_H_
  27. #define ETNAVIV_PRIV_H_
  28. #include <stdlib.h>
  29. #include <errno.h>
  30. #include <string.h>
  31. #include <unistd.h>
  32. #include <errno.h>
  33. #include <fcntl.h>
  34. #include <sys/ioctl.h>
  35. #include <pthread.h>
  36. #include <stdio.h>
  37. #include <assert.h>
  38. #include "libdrm_macros.h"
  39. #include "xf86drm.h"
  40. #include "xf86atomic.h"
  41. #include "util_double_list.h"
  42. #include "etnaviv_drmif.h"
  43. #include "etnaviv_drm.h"
  44. struct etna_bo_bucket {
  45. uint32_t size;
  46. struct list_head list;
  47. };
  48. struct etna_bo_cache {
  49. struct etna_bo_bucket cache_bucket[14 * 4];
  50. unsigned num_buckets;
  51. time_t time;
  52. };
  53. struct etna_device {
  54. int fd;
  55. atomic_t refcnt;
  56. /* tables to keep track of bo's, to avoid "evil-twin" etna_bo objects:
  57. *
  58. * handle_table: maps handle to etna_bo
  59. * name_table: maps flink name to etna_bo
  60. *
  61. * We end up needing two tables, because DRM_IOCTL_GEM_OPEN always
  62. * returns a new handle. So we need to figure out if the bo is already
  63. * open in the process first, before calling gem-open.
  64. */
  65. void *handle_table, *name_table;
  66. struct etna_bo_cache bo_cache;
  67. int closefd; /* call close(fd) upon destruction */
  68. };
  69. drm_private void etna_bo_cache_init(struct etna_bo_cache *cache);
  70. drm_private void etna_bo_cache_cleanup(struct etna_bo_cache *cache, time_t time);
  71. drm_private struct etna_bo *etna_bo_cache_alloc(struct etna_bo_cache *cache,
  72. uint32_t *size, uint32_t flags);
  73. drm_private int etna_bo_cache_free(struct etna_bo_cache *cache, struct etna_bo *bo);
  74. /* for where @table_lock is already held: */
  75. drm_private void etna_device_del_locked(struct etna_device *dev);
  76. /* a GEM buffer object allocated from the DRM device */
  77. struct etna_bo {
  78. struct etna_device *dev;
  79. void *map; /* userspace mmap'ing (if there is one) */
  80. uint32_t size;
  81. uint32_t handle;
  82. uint32_t flags;
  83. uint32_t name; /* flink global handle (DRI2 name) */
  84. uint64_t offset; /* offset to mmap() */
  85. atomic_t refcnt;
  86. /* in the common case, a bo won't be referenced by more than a single
  87. * command stream. So to avoid looping over all the bo's in the
  88. * reloc table to find the idx of a bo that might already be in the
  89. * table, we cache the idx in the bo. But in order to detect the
  90. * slow-path where bo is ref'd in multiple streams, we also must track
  91. * the current_stream for which the idx is valid. See bo2idx().
  92. */
  93. struct etna_cmd_stream *current_stream;
  94. uint32_t idx;
  95. int reuse;
  96. struct list_head list; /* bucket-list entry */
  97. time_t free_time; /* time when added to bucket-list */
  98. };
  99. struct etna_gpu {
  100. struct etna_device *dev;
  101. uint32_t core;
  102. uint32_t model;
  103. uint32_t revision;
  104. };
  105. struct etna_pipe {
  106. enum etna_pipe_id id;
  107. struct etna_gpu *gpu;
  108. };
  109. struct etna_cmd_stream_priv {
  110. struct etna_cmd_stream base;
  111. struct etna_pipe *pipe;
  112. uint32_t last_timestamp;
  113. /* submit ioctl related tables: */
  114. struct {
  115. /* bo's table: */
  116. struct drm_etnaviv_gem_submit_bo *bos;
  117. uint32_t nr_bos, max_bos;
  118. /* reloc's table: */
  119. struct drm_etnaviv_gem_submit_reloc *relocs;
  120. uint32_t nr_relocs, max_relocs;
  121. /* perf's table: */
  122. struct drm_etnaviv_gem_submit_pmr *pmrs;
  123. uint32_t nr_pmrs, max_pmrs;
  124. } submit;
  125. /* should have matching entries in submit.bos: */
  126. struct etna_bo **bos;
  127. uint32_t nr_bos, max_bos;
  128. /* notify callback if buffer reset happened */
  129. void (*reset_notify)(struct etna_cmd_stream *stream, void *priv);
  130. void *reset_notify_priv;
  131. };
  132. struct etna_perfmon {
  133. struct list_head domains;
  134. struct etna_pipe *pipe;
  135. };
  136. struct etna_perfmon_domain
  137. {
  138. struct list_head head;
  139. struct list_head signals;
  140. uint8_t id;
  141. char name[64];
  142. };
  143. struct etna_perfmon_signal
  144. {
  145. struct list_head head;
  146. struct etna_perfmon_domain *domain;
  147. uint8_t signal;
  148. char name[64];
  149. };
  150. #define ALIGN(v,a) (((v) + (a) - 1) & ~((a) - 1))
  151. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  152. #define enable_debug 1 /* TODO make dynamic */
  153. #define INFO_MSG(fmt, ...) \
  154. do { drmMsg("[I] "fmt " (%s:%d)\n", \
  155. ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
  156. #define DEBUG_MSG(fmt, ...) \
  157. do if (enable_debug) { drmMsg("[D] "fmt " (%s:%d)\n", \
  158. ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
  159. #define WARN_MSG(fmt, ...) \
  160. do { drmMsg("[W] "fmt " (%s:%d)\n", \
  161. ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
  162. #define ERROR_MSG(fmt, ...) \
  163. do { drmMsg("[E] " fmt " (%s:%d)\n", \
  164. ##__VA_ARGS__, __FUNCTION__, __LINE__); } while (0)
  165. #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
  166. static inline void get_abs_timeout(struct drm_etnaviv_timespec *tv, uint64_t ns)
  167. {
  168. struct timespec t;
  169. uint32_t s = ns / 1000000000;
  170. clock_gettime(CLOCK_MONOTONIC, &t);
  171. tv->tv_sec = t.tv_sec + s;
  172. tv->tv_nsec = t.tv_nsec + ns - (s * 1000000000);
  173. }
  174. #endif /* ETNAVIV_PRIV_H_ */