Merge branch 'upstream-gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / mesa / drivers / dri / nouveau_winsys / 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_device.h"
31 #include "pipe/nouveau/nouveau_channel.h"
32 #include "pipe/nouveau/nouveau_grobj.h"
33 #include "pipe/nouveau/nouveau_notifier.h"
34 #include "pipe/nouveau/nouveau_bo.h"
35 #include "pipe/nouveau/nouveau_resource.h"
36 #include "pipe/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 uint64_t next;
111 uint64_t handle;
112 uint32_t *ptr;
113 uint32_t flags;
114 uint32_t data;
115 uint32_t vor;
116 uint32_t tor;
117 };
118
119 struct nouveau_pushbuf_bo {
120 uint64_t next;
121 uint64_t handle;
122 uint64_t flags;
123 uint64_t relocs;
124 int nr_relocs;
125 };
126
127 struct nouveau_pushbuf_priv {
128 struct nouveau_pushbuf base;
129
130 unsigned nop_jump;
131 unsigned start;
132 unsigned size;
133
134 uint64_t buffers;
135 int nr_buffers;
136 };
137 #define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n))
138
139 #define pbbo_to_ptr(o) ((uint64_t)(unsigned long)(o))
140 #define ptr_to_pbbo(h) ((struct nouveau_pushbuf_bo *)(unsigned long)(h))
141 #define pbrel_to_ptr(o) ((uint64_t)(unsigned long)(o))
142 #define ptr_to_pbrel(h) ((struct nouveau_pushbuf_reloc *)(unsigned long)(h))
143 #define bo_to_ptr(o) ((uint64_t)(unsigned long)(o))
144 #define ptr_to_bo(h) ((struct nouveau_bo_priv *)(unsigned long)(h))
145
146 extern int
147 nouveau_pushbuf_init(struct nouveau_channel *);
148
149 extern int
150 nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
151
152 extern int
153 nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
154 struct nouveau_bo *, uint32_t data, uint32_t flags,
155 uint32_t vor, uint32_t tor);
156
157 struct nouveau_dma_priv {
158 uint32_t base;
159 uint32_t max;
160 uint32_t cur;
161 uint32_t put;
162 uint32_t free;
163
164 int push_free;
165 } dma;
166
167 struct nouveau_channel_priv {
168 struct nouveau_channel base;
169
170 struct drm_nouveau_channel_alloc drm;
171
172 uint32_t *pushbuf;
173 void *notifier_block;
174
175 volatile uint32_t *user;
176 volatile uint32_t *put;
177 volatile uint32_t *get;
178 volatile uint32_t *ref_cnt;
179
180 struct nouveau_dma_priv dma_master;
181 struct nouveau_dma_priv dma_bufmgr;
182 struct nouveau_dma_priv *dma;
183
184 struct nouveau_fence *fence_head;
185 struct nouveau_fence *fence_tail;
186 uint32_t fence_sequence;
187
188 struct nouveau_pushbuf_priv pb;
189
190 unsigned user_charge;
191 };
192 #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
193
194 extern int
195 nouveau_channel_alloc(struct nouveau_device *, uint32_t fb, uint32_t tt,
196 struct nouveau_channel **);
197
198 extern void
199 nouveau_channel_free(struct nouveau_channel **);
200
201 struct nouveau_grobj_priv {
202 struct nouveau_grobj base;
203 };
204 #define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
205
206 extern int nouveau_grobj_alloc(struct nouveau_channel *, uint32_t handle,
207 int class, struct nouveau_grobj **);
208 extern int nouveau_grobj_ref(struct nouveau_channel *, uint32_t handle,
209 struct nouveau_grobj **);
210 extern void nouveau_grobj_free(struct nouveau_grobj **);
211
212
213 struct nouveau_notifier_priv {
214 struct nouveau_notifier base;
215
216 struct drm_nouveau_notifierobj_alloc drm;
217 volatile void *map;
218 };
219 #define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
220
221 extern int
222 nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle, int count,
223 struct nouveau_notifier **);
224
225 extern void
226 nouveau_notifier_free(struct nouveau_notifier **);
227
228 extern void
229 nouveau_notifier_reset(struct nouveau_notifier *, int id);
230
231 extern uint32_t
232 nouveau_notifier_status(struct nouveau_notifier *, int id);
233
234 extern uint32_t
235 nouveau_notifier_return_val(struct nouveau_notifier *, int id);
236
237 extern int
238 nouveau_notifier_wait_status(struct nouveau_notifier *, int id, int status,
239 int timeout);
240
241 struct nouveau_bo_priv {
242 struct nouveau_bo base;
243
244 struct nouveau_fence *fence;
245 struct nouveau_fence *wr_fence;
246
247 struct drm_nouveau_mem_alloc drm;
248 void *map;
249
250 void *sysmem;
251 int user;
252
253 int refcount;
254
255 uint64_t offset;
256 uint64_t flags;
257 };
258 #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
259
260 extern int
261 nouveau_bo_init(struct nouveau_device *);
262
263 extern void
264 nouveau_bo_takedown(struct nouveau_device *);
265
266 extern int
267 nouveau_bo_new(struct nouveau_device *, uint32_t flags, int align, int size,
268 struct nouveau_bo **);
269
270 extern int
271 nouveau_bo_user(struct nouveau_device *, void *ptr, int size,
272 struct nouveau_bo **);
273
274 extern int
275 nouveau_bo_ref(struct nouveau_device *, uint64_t handle, struct nouveau_bo **);
276
277 extern int
278 nouveau_bo_set_status(struct nouveau_bo *, uint32_t flags);
279
280 extern void
281 nouveau_bo_del(struct nouveau_bo **);
282
283 extern int
284 nouveau_bo_map(struct nouveau_bo *, uint32_t flags);
285
286 extern void
287 nouveau_bo_unmap(struct nouveau_bo *);
288
289 extern int
290 nouveau_bo_validate(struct nouveau_channel *, struct nouveau_bo *,
291 struct nouveau_fence *fence, uint32_t flags);
292
293 extern int
294 nouveau_resource_init(struct nouveau_resource **heap, unsigned start,
295 unsigned size);
296
297 extern int
298 nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv,
299 struct nouveau_resource **);
300
301 extern void
302 nouveau_resource_free(struct nouveau_resource **);
303
304 #endif