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/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"
38 struct nouveau_device_priv
{
39 struct nouveau_device base
;
46 struct drm_nouveau_mem_alloc sa
;
48 struct nouveau_resource
*sa_heap
;
50 #define nouveau_device(n) ((struct nouveau_device_priv *)(n))
53 nouveau_device_open_existing(struct nouveau_device
**, int close
,
54 int fd
, drm_context_t ctx
);
57 nouveau_device_open(struct nouveau_device
**, const char *busid
);
60 nouveau_device_close(struct nouveau_device
**);
63 nouveau_device_get_param(struct nouveau_device
*, uint64_t param
, uint64_t *v
);
66 nouveau_device_set_param(struct nouveau_device
*, uint64_t param
, uint64_t val
);
68 struct nouveau_fence
{
69 struct nouveau_channel
*channel
;
72 struct nouveau_fence_cb
{
73 struct nouveau_fence_cb
*next
;
78 struct nouveau_fence_priv
{
79 struct nouveau_fence base
;
82 struct nouveau_fence
*next
;
83 struct nouveau_fence_cb
*signal_cb
;
89 #define nouveau_fence(n) ((struct nouveau_fence_priv *)(n))
92 nouveau_fence_new(struct nouveau_channel
*, struct nouveau_fence
**);
95 nouveau_fence_ref(struct nouveau_fence
*, struct nouveau_fence
**);
98 nouveau_fence_signal_cb(struct nouveau_fence
*, void (*)(void *), void *);
101 nouveau_fence_emit(struct nouveau_fence
*);
104 nouveau_fence_wait(struct nouveau_fence
**);
107 nouveau_fence_flush(struct nouveau_channel
*);
109 struct nouveau_pushbuf_reloc
{
110 struct nouveau_pushbuf_bo
*pbbo
;
118 struct nouveau_pushbuf_bo
{
119 struct nouveau_channel
*channel
;
120 struct nouveau_bo
*bo
;
125 #define NOUVEAU_PUSHBUF_MAX_BUFFERS 1024
126 #define NOUVEAU_PUSHBUF_MAX_RELOCS 1024
127 struct nouveau_pushbuf_priv
{
128 struct nouveau_pushbuf base
;
130 struct nouveau_fence
*fence
;
136 struct nouveau_pushbuf_bo
*buffers
;
138 struct nouveau_pushbuf_reloc
*relocs
;
141 #define nouveau_pushbuf(n) ((struct nouveau_pushbuf_priv *)(n))
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))
151 nouveau_pushbuf_init(struct nouveau_channel
*);
154 nouveau_pushbuf_flush(struct nouveau_channel
*, unsigned min
);
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
);
161 struct nouveau_dma_priv
{
171 struct nouveau_channel_priv
{
172 struct nouveau_channel base
;
174 struct drm_nouveau_channel_alloc drm
;
177 void *notifier_block
;
179 volatile uint32_t *user
;
180 volatile uint32_t *put
;
181 volatile uint32_t *get
;
182 volatile uint32_t *ref_cnt
;
184 struct nouveau_dma_priv dma_master
;
185 struct nouveau_dma_priv dma_bufmgr
;
186 struct nouveau_dma_priv
*dma
;
188 struct nouveau_fence
*fence_head
;
189 struct nouveau_fence
*fence_tail
;
190 uint32_t fence_sequence
;
192 struct nouveau_pushbuf_priv pb
;
194 unsigned user_charge
;
196 #define nouveau_channel(n) ((struct nouveau_channel_priv *)(n))
199 nouveau_channel_alloc(struct nouveau_device
*, uint32_t fb
, uint32_t tt
,
200 struct nouveau_channel
**);
203 nouveau_channel_free(struct nouveau_channel
**);
205 struct nouveau_grobj_priv
{
206 struct nouveau_grobj base
;
208 #define nouveau_grobj(n) ((struct nouveau_grobj_priv *)(n))
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
**);
217 struct nouveau_notifier_priv
{
218 struct nouveau_notifier base
;
220 struct drm_nouveau_notifierobj_alloc drm
;
223 #define nouveau_notifier(n) ((struct nouveau_notifier_priv *)(n))
226 nouveau_notifier_alloc(struct nouveau_channel
*, uint32_t handle
, int count
,
227 struct nouveau_notifier
**);
230 nouveau_notifier_free(struct nouveau_notifier
**);
233 nouveau_notifier_reset(struct nouveau_notifier
*, int id
);
236 nouveau_notifier_status(struct nouveau_notifier
*, int id
);
239 nouveau_notifier_return_val(struct nouveau_notifier
*, int id
);
242 nouveau_notifier_wait_status(struct nouveau_notifier
*, int id
, int status
,
245 struct nouveau_bo_priv
{
246 struct nouveau_bo base
;
248 struct nouveau_pushbuf_bo
*pending
;
249 struct nouveau_fence
*fence
;
250 struct nouveau_fence
*wr_fence
;
252 struct drm_nouveau_mem_alloc drm
;
264 #define nouveau_bo(n) ((struct nouveau_bo_priv *)(n))
267 nouveau_bo_init(struct nouveau_device
*);
270 nouveau_bo_takedown(struct nouveau_device
*);
273 nouveau_bo_new(struct nouveau_device
*, uint32_t flags
, int align
, int size
,
274 struct nouveau_bo
**);
277 nouveau_bo_user(struct nouveau_device
*, void *ptr
, int size
,
278 struct nouveau_bo
**);
281 nouveau_bo_ref(struct nouveau_device
*, uint64_t handle
, struct nouveau_bo
**);
284 nouveau_bo_set_status(struct nouveau_bo
*, uint32_t flags
);
287 nouveau_bo_del(struct nouveau_bo
**);
290 nouveau_bo_map(struct nouveau_bo
*, uint32_t flags
);
293 nouveau_bo_unmap(struct nouveau_bo
*);
296 nouveau_bo_validate(struct nouveau_channel
*, struct nouveau_bo
*,
300 nouveau_resource_init(struct nouveau_resource
**heap
, unsigned start
,
304 nouveau_resource_alloc(struct nouveau_resource
*heap
, int size
, void *priv
,
305 struct nouveau_resource
**);
308 nouveau_resource_free(struct nouveau_resource
**);