Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / winsys / dri / nouveau / nouveau_drmif.h
1 /*
2 * Copyright 2007 Nouveau 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 shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #ifndef __NOUVEAU_DRMIF_H__
24 #define __NOUVEAU_DRMIF_H__
25
26 #include <stdint.h>
27 #include <xf86drm.h>
28 #include <nouveau_drm.h>
29
30 #include "nouveau/nouveau_device.h"
31 #include "nouveau/nouveau_channel.h"
32 #include "nouveau/nouveau_grobj.h"
33 #include "nouveau/nouveau_notifier.h"
34 #include "nouveau/nouveau_bo.h"
35 #include "nouveau/nouveau_resource.h"
36 #include "nouveau/nouveau_pushbuf.h"
37
38 struct nouveau_device_priv {
39 struct nouveau_device base;
40
41 int fd;
42 drm_context_t ctx;
43 drmLock *lock;
44 int needs_close;
45
46 struct drm_nouveau_mem_alloc sa;
47 void *sa_map;
48 struct nouveau_resource *sa_heap;
49 };
50 #define nouveau_device(n) ((struct nouveau_device_priv *)(n))
51
52 extern int
53 nouveau_device_open_existing(struct nouveau_device **, int close,
54 int fd, drm_context_t ctx);
55
56 extern int
57 nouveau_device_open(struct nouveau_device **, const char *busid);
58
59 extern void
60 nouveau_device_close(struct nouveau_device **);
61
62 extern int
63 nouveau_device_get_param(struct nouveau_device *, uint64_t param, uint64_t *v);
64
65 extern int
66 nouveau_device_set_param(struct nouveau_device *, uint64_t param, uint64_t val);
67
68 struct nouveau_fence {
69 struct nouveau_channel *channel;
70 };
71
72 struct nouveau_fence_cb {
73 struct nouveau_fence_cb *next;
74 void (*func)(void *);
75 void *priv;
76 };
77
78 struct nouveau_fence_priv {
79 struct nouveau_fence base;
80 int refcount;
81
82 struct nouveau_fence *next;
83 struct nouveau_fence_cb *signal_cb;
84
85 uint32_t sequence;
86 int emitted;
87 int signalled;
88 };
89 #define nouveau_fence(n) ((struct nouveau_fence_priv *)(n))
90
91 extern int
92 nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **);
93
94 extern int
95 nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **);
96
97 extern int
98 nouveau_fence_signal_cb(struct nouveau_fence *, void (*)(void *), void *);
99
100 extern void
101 nouveau_fence_emit(struct nouveau_fence *);
102
103 extern int
104 nouveau_fence_wait(struct nouveau_fence **);
105
106 extern void
107 nouveau_fence_flush(struct nouveau_channel *);
108
109 struct nouveau_pushbuf_reloc {
110 struct nouveau_pushbuf_bo *pbbo;
111 uint32_t *ptr;
112 uint32_t flags;
113 uint32_t data;
114 uint32_t vor;
115 uint32_t tor;
116 };
117
118 struct nouveau_pushbuf_bo {
119 struct nouveau_channel *channel;
120 struct nouveau_bo *bo;
121 unsigned flags;
122 unsigned handled;
123 };
124
125 #define NOUVEAU_PUSHBUF_MAX_BUFFERS 1024
126 #define NOUVEAU_PUSHBUF_MAX_RELOCS 1024
127 struct nouveau_pushbuf_priv {
128 struct nouveau_pushbuf base;
129
130 struct nouveau_fence *fence;
131
132 unsigned nop_jump;
133 unsigned start;
134 unsigned size;
135
136 struct nouveau_pushbuf_bo *buffers;
137 unsigned nr_buffers;
138 struct nouveau_pushbuf_reloc *relocs;
139 unsigned nr_relocs;
140 };
141 #define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n))
142
143 #define pbbo_to_ptr(o) ((uint64_t)(unsigned long)(o))
144 #define ptr_to_pbbo(h) ((struct nouveau_pushbuf_bo *)(unsigned long)(h))
145 #define pbrel_to_ptr(o) ((uint64_t)(unsigned long)(o))
146 #define ptr_to_pbrel(h) ((struct nouveau_pushbuf_reloc *)(unsigned long)(h))
147 #define bo_to_ptr(o) ((uint64_t)(unsigned long)(o))
148 #define ptr_to_bo(h) ((struct nouveau_bo_priv *)(unsigned long)(h))
149
150 extern int
151 nouveau_pushbuf_init(struct nouveau_channel *);
152
153 extern int
154 nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
155
156 extern int
157 nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
158 struct nouveau_bo *, uint32_t data, uint32_t flags,
159 uint32_t vor, uint32_t tor);
160
161 struct nouveau_dma_priv {
162 uint32_t base;
163 uint32_t max;
164 uint32_t cur;
165 uint32_t put;
166 uint32_t free;
167
168 int push_free;
169 } dma;
170
171 struct nouveau_channel_priv {
172 struct nouveau_channel base;
173
174 struct drm_nouveau_channel_alloc drm;
175
176 uint32_t *pushbuf;
177 void *notifier_block;
178
179 volatile uint32_t *user;
180 volatile uint32_t *put;
181 volatile uint32_t *get;
182 volatile uint32_t *ref_cnt;
183
184 struct nouveau_dma_priv dma_master;
185 struct nouveau_dma_priv dma_bufmgr;
186 struct nouveau_dma_priv *dma;
187
188 struct nouveau_fence *fence_head;
189 struct nouveau_fence *fence_tail;
190 uint32_t fence_sequence;
191
192 struct nouveau_pushbuf_priv pb;
193
194 unsigned user_charge;
195 };
196 #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
197
198 extern int
199 nouveau_channel_alloc(struct nouveau_device *, uint32_t fb, uint32_t tt,
200 struct nouveau_channel **);
201
202 extern void
203 nouveau_channel_free(struct nouveau_channel **);
204
205 struct nouveau_grobj_priv {
206 struct nouveau_grobj base;
207 };
208 #define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
209
210 extern int nouveau_grobj_alloc(struct nouveau_channel *, uint32_t handle,
211 int class, struct nouveau_grobj **);
212 extern int nouveau_grobj_ref(struct nouveau_channel *, uint32_t handle,
213 struct nouveau_grobj **);
214 extern void nouveau_grobj_free(struct nouveau_grobj **);
215
216
217 struct nouveau_notifier_priv {
218 struct nouveau_notifier base;
219
220 struct drm_nouveau_notifierobj_alloc drm;
221 volatile void *map;
222 };
223 #define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
224
225 extern int
226 nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle, int count,
227 struct nouveau_notifier **);
228
229 extern void
230 nouveau_notifier_free(struct nouveau_notifier **);
231
232 extern void
233 nouveau_notifier_reset(struct nouveau_notifier *, int id);
234
235 extern uint32_t
236 nouveau_notifier_status(struct nouveau_notifier *, int id);
237
238 extern uint32_t
239 nouveau_notifier_return_val(struct nouveau_notifier *, int id);
240
241 extern int
242 nouveau_notifier_wait_status(struct nouveau_notifier *, int id, int status,
243 int timeout);
244
245 struct nouveau_bo_priv {
246 struct nouveau_bo base;
247
248 struct nouveau_pushbuf_bo *pending;
249 struct nouveau_fence *fence;
250 struct nouveau_fence *wr_fence;
251
252 struct drm_nouveau_mem_alloc drm;
253 void *map;
254
255 void *sysmem;
256 int user;
257
258 int refcount;
259
260 uint64_t offset;
261 uint64_t flags;
262 int tiled;
263 };
264 #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
265
266 extern int
267 nouveau_bo_init(struct nouveau_device *);
268
269 extern void
270 nouveau_bo_takedown(struct nouveau_device *);
271
272 extern int
273 nouveau_bo_new(struct nouveau_device *, uint32_t flags, int align, int size,
274 struct nouveau_bo **);
275
276 extern int
277 nouveau_bo_user(struct nouveau_device *, void *ptr, int size,
278 struct nouveau_bo **);
279
280 extern int
281 nouveau_bo_ref(struct nouveau_device *, uint64_t handle, struct nouveau_bo **);
282
283 extern int
284 nouveau_bo_set_status(struct nouveau_bo *, uint32_t flags);
285
286 extern void
287 nouveau_bo_del(struct nouveau_bo **);
288
289 extern int
290 nouveau_bo_map(struct nouveau_bo *, uint32_t flags);
291
292 extern void
293 nouveau_bo_unmap(struct nouveau_bo *);
294
295 extern int
296 nouveau_bo_validate(struct nouveau_channel *, struct nouveau_bo *,
297 uint32_t flags);
298
299 extern int
300 nouveau_resource_init(struct nouveau_resource **heap, unsigned start,
301 unsigned size);
302
303 extern int
304 nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv,
305 struct nouveau_resource **);
306
307 extern void
308 nouveau_resource_free(struct nouveau_resource **);
309
310 #endif