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