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_PUSHBUF_H__
24 #define __NOUVEAU_PUSHBUF_H__
29 #include "nouveau_bo.h"
30 #include "nouveau_grobj.h"
32 struct nouveau_pushbuf
{
33 struct nouveau_channel
*channel
;
40 nouveau_pushbuf_flush(struct nouveau_channel
*, unsigned min
);
43 nouveau_pushbuf_emit_reloc(struct nouveau_channel
*, void *ptr
,
44 struct nouveau_bo
*, uint32_t data
, uint32_t flags
,
45 uint32_t vor
, uint32_t tor
);
47 /* Push buffer access macros */
48 static __inline__
void
49 OUT_RING(struct nouveau_channel
*chan
, unsigned data
)
51 *(chan
->pushbuf
->cur
++) = (data
);
54 static __inline__
void
55 OUT_RINGp(struct nouveau_channel
*chan
, const void *data
, unsigned size
)
57 memcpy(chan
->pushbuf
->cur
, data
, size
* 4);
58 chan
->pushbuf
->cur
+= size
;
61 static __inline__
void
62 OUT_RINGf(struct nouveau_channel
*chan
, float f
)
64 union { uint32_t i
; float f
; } c
;
69 static __inline__
unsigned
70 AVAIL_RING(struct nouveau_channel
*chan
)
72 return chan
->pushbuf
->remaining
;
75 static __inline__
void
76 WAIT_RING(struct nouveau_channel
*chan
, unsigned size
)
78 if (chan
->pushbuf
->remaining
< size
)
79 nouveau_pushbuf_flush(chan
, size
);
82 static __inline__
void
83 BEGIN_RING(struct nouveau_channel
*chan
, struct nouveau_grobj
*gr
,
84 unsigned mthd
, unsigned size
)
86 if (gr
->bound
== NOUVEAU_GROBJ_UNBOUND
)
87 nouveau_grobj_autobind(gr
);
88 chan
->subc
[gr
->subc
].sequence
= chan
->subc_sequence
++;
90 WAIT_RING(chan
, size
+ 1);
91 OUT_RING(chan
, (gr
->subc
<< 13) | (size
<< 18) | mthd
);
92 chan
->pushbuf
->remaining
-= (size
+ 1);
95 static __inline__
void
96 FIRE_RING(struct nouveau_channel
*chan
)
98 nouveau_pushbuf_flush(chan
, 0);
101 static __inline__
void
102 BIND_RING(struct nouveau_channel
*chan
, struct nouveau_grobj
*gr
, unsigned sc
)
104 struct nouveau_subchannel
*subc
= &gr
->channel
->subc
[sc
];
107 if (subc
->gr
->bound
== NOUVEAU_GROBJ_BOUND_EXPLICIT
)
109 subc
->gr
->bound
= NOUVEAU_GROBJ_UNBOUND
;
113 subc
->gr
->bound
= NOUVEAU_GROBJ_BOUND_EXPLICIT
;
115 BEGIN_RING(chan
, gr
, 0x0000, 1);
116 OUT_RING (chan
, gr
->handle
);
119 static __inline__
void
120 OUT_RELOC(struct nouveau_channel
*chan
, struct nouveau_bo
*bo
,
121 unsigned data
, unsigned flags
, unsigned vor
, unsigned tor
)
123 nouveau_pushbuf_emit_reloc(chan
, chan
->pushbuf
->cur
++, bo
,
124 data
, flags
, vor
, tor
);
127 /* Raw data + flags depending on FB/TT buffer */
128 static __inline__
void
129 OUT_RELOCd(struct nouveau_channel
*chan
, struct nouveau_bo
*bo
,
130 unsigned data
, unsigned flags
, unsigned vor
, unsigned tor
)
132 OUT_RELOC(chan
, bo
, data
, flags
| NOUVEAU_BO_OR
, vor
, tor
);
135 /* FB/TT object handle */
136 static __inline__
void
137 OUT_RELOCo(struct nouveau_channel
*chan
, struct nouveau_bo
*bo
,
140 OUT_RELOC(chan
, bo
, 0, flags
| NOUVEAU_BO_OR
,
141 chan
->vram
->handle
, chan
->gart
->handle
);
144 /* Low 32-bits of offset */
145 static __inline__
void
146 OUT_RELOCl(struct nouveau_channel
*chan
, struct nouveau_bo
*bo
,
147 unsigned delta
, unsigned flags
)
149 OUT_RELOC(chan
, bo
, delta
, flags
| NOUVEAU_BO_LOW
, 0, 0);
152 /* High 32-bits of offset */
153 static __inline__
void
154 OUT_RELOCh(struct nouveau_channel
*chan
, struct nouveau_bo
*bo
,
155 unsigned delta
, unsigned flags
)
157 OUT_RELOC(chan
, bo
, delta
, flags
| NOUVEAU_BO_HIGH
, 0, 0);