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