2 * Copyright 2007 Nouveau Project
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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
23 #ifndef __NOUVEAU_DRMIF_H__
24 #define __NOUVEAU_DRMIF_H__
28 #include <nouveau_drm.h>
30 #include "nouveau_device.h"
31 #include "nouveau_channel.h"
32 #include "nouveau_grobj.h"
33 #include "nouveau_notifier.h"
34 #include "nouveau_bo.h"
35 #include "nouveau_resource.h"
36 #include "nouveau_pushbuf.h"
37 #include "nouveau_local.h"
39 struct nouveau_device_priv {
40 struct nouveau_device base;
47 #define nouveau_device(n) ((struct nouveau_device_priv *)(n))
50 nouveau_device_open_existing(struct nouveau_device **, int close,
51 int fd, drm_context_t ctx);
54 nouveau_device_open(struct nouveau_device **, const char *busid);
57 nouveau_device_close(struct nouveau_device **);
60 nouveau_device_get_param(struct nouveau_device *, uint64_t param, uint64_t *v);
63 nouveau_device_set_param(struct nouveau_device *, uint64_t param, uint64_t val);
65 struct nouveau_fence {
66 struct nouveau_channel *channel;
69 struct nouveau_fence_cb {
70 struct nouveau_fence_cb *next;
75 struct nouveau_fence_priv {
76 struct nouveau_fence base;
79 struct nouveau_fence *next;
80 struct nouveau_fence_cb *signal_cb;
86 #define nouveau_fence(n) ((struct nouveau_fence_priv *)(n))
89 nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **);
92 nouveau_fence_ref(struct nouveau_fence *, struct nouveau_fence **);
95 nouveau_fence_signal_cb(struct nouveau_fence *, void (*)(void *), void *);
98 nouveau_fence_emit(struct nouveau_fence *);
101 nouveau_fence_wait(struct nouveau_fence **);
104 nouveau_fence_flush(struct nouveau_channel *);
106 #define NOUVEAU_PUSHBUF_MAX_BUFFERS 1024
107 #define NOUVEAU_PUSHBUF_MAX_RELOCS 1024
108 struct nouveau_pushbuf_priv {
109 struct nouveau_pushbuf base;
114 struct drm_nouveau_gem_pushbuf_bo *buffers;
116 struct drm_nouveau_gem_pushbuf_reloc *relocs;
119 #define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n))
121 #define pbbo_to_ptr(o) ((uint64_t)(unsigned long)(o))
122 #define ptr_to_pbbo(h) ((struct nouveau_pushbuf_bo *)(unsigned long)(h))
123 #define pbrel_to_ptr(o) ((uint64_t)(unsigned long)(o))
124 #define ptr_to_pbrel(h) ((struct nouveau_pushbuf_reloc *)(unsigned long)(h))
125 #define bo_to_ptr(o) ((uint64_t)(unsigned long)(o))
126 #define ptr_to_bo(h) ((struct nouveau_bo_priv *)(unsigned long)(h))
129 nouveau_pushbuf_init(struct nouveau_channel *);
132 nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
135 nouveau_pushbuf_emit_reloc(struct nouveau_channel *, void *ptr,
136 struct nouveau_bo *, uint32_t data, uint32_t flags,
137 uint32_t vor, uint32_t tor);
139 struct nouveau_channel_priv {
140 struct nouveau_channel base;
142 struct drm_nouveau_channel_alloc drm;
144 void *notifier_block;
146 struct nouveau_fence *fence_head;
147 struct nouveau_fence *fence_tail;
148 uint32_t fence_sequence;
150 struct nouveau_grobj *fence_grobj;
151 struct nouveau_notifier *fence_ntfy;
153 struct nouveau_pushbuf_priv pb;
155 unsigned user_charge;
157 #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
160 nouveau_channel_alloc(struct nouveau_device *, uint32_t fb, uint32_t tt,
161 struct nouveau_channel **);
164 nouveau_channel_free(struct nouveau_channel **);
166 struct nouveau_grobj_priv {
167 struct nouveau_grobj base;
169 #define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
171 NOUVEAU_PRIVATE int nouveau_grobj_alloc(struct nouveau_channel *, uint32_t handle,
172 int class, struct nouveau_grobj **);
173 NOUVEAU_PRIVATE int nouveau_grobj_ref(struct nouveau_channel *, uint32_t handle,
174 struct nouveau_grobj **);
175 NOUVEAU_PRIVATE void nouveau_grobj_free(struct nouveau_grobj **);
178 struct nouveau_notifier_priv {
179 struct nouveau_notifier base;
181 struct drm_nouveau_notifierobj_alloc drm;
184 #define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
187 nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle, int count,
188 struct nouveau_notifier **);
191 nouveau_notifier_free(struct nouveau_notifier **);
194 nouveau_notifier_reset(struct nouveau_notifier *, int id);
196 NOUVEAU_PRIVATE uint32_t
197 nouveau_notifier_status(struct nouveau_notifier *, int id);
199 NOUVEAU_PRIVATE uint32_t
200 nouveau_notifier_return_val(struct nouveau_notifier *, int id);
203 nouveau_notifier_wait_status(struct nouveau_notifier *, int id, int status,
206 struct nouveau_bo_priv {
207 struct nouveau_bo base;
210 /* Buffer configuration + usage hints */
217 struct drm_nouveau_gem_pushbuf_bo *pending;
218 struct nouveau_channel *pending_channel;
219 struct nouveau_fence *fence;
220 struct nouveau_fence *wr_fence;
222 /* Userspace object */
226 uint32_t global_handle;
230 /* Last known information from kernel on buffer status */
235 #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
238 nouveau_bo_init(struct nouveau_device *);
241 nouveau_bo_takedown(struct nouveau_device *);
244 nouveau_bo_new(struct nouveau_device *, uint32_t flags, int align, int size,
245 struct nouveau_bo **);
248 nouveau_bo_user(struct nouveau_device *, void *ptr, int size,
249 struct nouveau_bo **);
252 nouveau_bo_ref_handle(struct nouveau_device *, uint32_t handle,
253 struct nouveau_bo **);
256 nouveau_bo_ref(struct nouveau_bo *, struct nouveau_bo **);
259 nouveau_bo_map(struct nouveau_bo *, uint32_t flags);
262 nouveau_bo_unmap(struct nouveau_bo *);
265 nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
268 nouveau_bo_unpin(struct nouveau_bo *);
270 NOUVEAU_PRIVATE uint64_t
271 nouveau_bo_get_drm_map(struct nouveau_bo *);
274 nouveau_resource_init(struct nouveau_resource **heap, unsigned start,
278 nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv,
279 struct nouveau_resource **);
282 nouveau_resource_free(struct nouveau_resource **);
284 NOUVEAU_PRIVATE struct drm_nouveau_gem_pushbuf_bo *
285 nouveau_bo_emit_buffer(struct nouveau_channel *, struct nouveau_bo *);