1
0

private.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef __NOUVEAU_LIBDRM_PRIVATE_H__
  2. #define __NOUVEAU_LIBDRM_PRIVATE_H__
  3. #include <stdio.h>
  4. #include <libdrm_macros.h>
  5. #include <xf86drm.h>
  6. #include <xf86atomic.h>
  7. #include <pthread.h>
  8. #include "nouveau_drm.h"
  9. #include "nouveau.h"
  10. /*
  11. * 0x00000001 dump all pushbuffers
  12. * 0x00000002 submit pushbuffers synchronously
  13. * 0x80000000 if compiled with SIMULATE return -EINVAL for all pb submissions
  14. */
  15. drm_private extern uint32_t nouveau_debug;
  16. drm_private extern FILE *nouveau_out;
  17. #define dbg_on(lvl) (nouveau_debug & (1 << lvl))
  18. #define dbg(lvl, fmt, args...) do { \
  19. if (dbg_on((lvl))) \
  20. fprintf(nouveau_out, "nouveau: "fmt, ##args); \
  21. } while(0)
  22. #define err(fmt, args...) fprintf(nouveau_out, "nouveau: "fmt, ##args)
  23. struct nouveau_client_kref {
  24. struct drm_nouveau_gem_pushbuf_bo *kref;
  25. struct nouveau_pushbuf *push;
  26. };
  27. struct nouveau_client_priv {
  28. struct nouveau_client base;
  29. struct nouveau_client_kref *kref;
  30. unsigned kref_nr;
  31. };
  32. static inline struct nouveau_client_priv *
  33. nouveau_client(struct nouveau_client *client)
  34. {
  35. return (struct nouveau_client_priv *)client;
  36. }
  37. static inline struct drm_nouveau_gem_pushbuf_bo *
  38. cli_kref_get(struct nouveau_client *client, struct nouveau_bo *bo)
  39. {
  40. struct nouveau_client_priv *pcli = nouveau_client(client);
  41. struct drm_nouveau_gem_pushbuf_bo *kref = NULL;
  42. if (pcli->kref_nr > bo->handle)
  43. kref = pcli->kref[bo->handle].kref;
  44. return kref;
  45. }
  46. static inline struct nouveau_pushbuf *
  47. cli_push_get(struct nouveau_client *client, struct nouveau_bo *bo)
  48. {
  49. struct nouveau_client_priv *pcli = nouveau_client(client);
  50. struct nouveau_pushbuf *push = NULL;
  51. if (pcli->kref_nr > bo->handle)
  52. push = pcli->kref[bo->handle].push;
  53. return push;
  54. }
  55. static inline void
  56. cli_kref_set(struct nouveau_client *client, struct nouveau_bo *bo,
  57. struct drm_nouveau_gem_pushbuf_bo *kref,
  58. struct nouveau_pushbuf *push)
  59. {
  60. struct nouveau_client_priv *pcli = nouveau_client(client);
  61. if (pcli->kref_nr <= bo->handle) {
  62. pcli->kref = realloc(pcli->kref,
  63. sizeof(*pcli->kref) * bo->handle * 2);
  64. while (pcli->kref_nr < bo->handle * 2) {
  65. pcli->kref[pcli->kref_nr].kref = NULL;
  66. pcli->kref[pcli->kref_nr].push = NULL;
  67. pcli->kref_nr++;
  68. }
  69. }
  70. pcli->kref[bo->handle].kref = kref;
  71. pcli->kref[bo->handle].push = push;
  72. }
  73. struct nouveau_bo_priv {
  74. struct nouveau_bo base;
  75. struct nouveau_list head;
  76. atomic_t refcnt;
  77. uint64_t map_handle;
  78. uint32_t name;
  79. uint32_t access;
  80. };
  81. static inline struct nouveau_bo_priv *
  82. nouveau_bo(struct nouveau_bo *bo)
  83. {
  84. return (struct nouveau_bo_priv *)bo;
  85. }
  86. struct nouveau_device_priv {
  87. struct nouveau_device base;
  88. int close;
  89. pthread_mutex_t lock;
  90. struct nouveau_list bo_list;
  91. uint32_t *client;
  92. int nr_client;
  93. bool have_bo_usage;
  94. int gart_limit_percent, vram_limit_percent;
  95. };
  96. static inline struct nouveau_device_priv *
  97. nouveau_device(struct nouveau_device *dev)
  98. {
  99. return (struct nouveau_device_priv *)dev;
  100. }
  101. int
  102. nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t);
  103. /* abi16.c */
  104. drm_private bool abi16_object(struct nouveau_object *, int (**)(struct nouveau_object *));
  105. drm_private void abi16_delete(struct nouveau_object *);
  106. drm_private int abi16_sclass(struct nouveau_object *, struct nouveau_sclass **);
  107. drm_private void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *);
  108. drm_private int abi16_bo_init(struct nouveau_bo *, uint32_t alignment,
  109. union nouveau_bo_config *);
  110. #endif