Tizen 2.0 Release
[profile/ivi/osmesa.git] / src / gallium / drivers / nv50 / nv50_winsys.h
1
2 #ifndef __NV50_WINSYS_H__
3 #define __NV50_WINSYS_H__
4
5 #include <stdint.h>
6 #include <unistd.h>
7
8 #include "pipe/p_defines.h"
9
10 #include "nouveau/nouveau_bo.h"
11 #include "nouveau/nouveau_channel.h"
12 #include "nouveau/nouveau_grobj.h"
13 #include "nouveau/nouveau_device.h"
14 #include "nouveau/nouveau_resource.h"
15 #include "nouveau/nouveau_pushbuf.h"
16 #include "nouveau/nouveau_reloc.h"
17 #include "nouveau/nouveau_notifier.h"
18
19 #include "nouveau/nouveau_buffer.h"
20
21 #ifndef NV04_PFIFO_MAX_PACKET_LEN
22 #define NV04_PFIFO_MAX_PACKET_LEN 2047
23 #endif
24
25 #define NV50_SUBCH_3D 5
26 #define NV50_SUBCH_2D 6
27 #define NV50_SUBCH_MF 7
28
29 #define NV50_MF_(n) NV50_M2MF_##n
30
31 #define RING_3D(n) ((NV50_SUBCH_3D << 13) | NV50_3D_##n)
32 #define RING_2D(n) ((NV50_SUBCH_2D << 13) | NV50_2D_##n)
33 #define RING_MF(n) ((NV50_SUBCH_MF << 13) | NV50_MF_(n))
34
35 #define RING_3D_(m) ((NV50_SUBCH_3D << 13) | (m))
36 #define RING_2D_(m) ((NV50_SUBCH_2D << 13) | (m))
37 #define RING_MF_(m) ((NV50_SUBCH_MF << 13) | (m))
38
39 #define RING_GR(gr, m) (((gr)->subc << 13) | (m))
40
41 int nouveau_pushbuf_flush(struct nouveau_channel *, unsigned min);
42
43 static inline uint32_t
44 nouveau_bo_tile_layout(struct nouveau_bo *bo)
45 {
46    return bo->tile_flags & NOUVEAU_BO_TILE_LAYOUT_MASK;
47 }
48
49 static INLINE void
50 nouveau_bo_validate(struct nouveau_channel *chan,
51                     struct nouveau_bo *bo, unsigned flags)
52 {
53    nouveau_reloc_emit(chan, NULL, 0, NULL, bo, 0, 0, flags, 0, 0);
54 }
55
56 /* incremental methods */
57 static INLINE void
58 BEGIN_RING(struct nouveau_channel *chan, uint32_t mthd, unsigned size)
59 {
60    WAIT_RING(chan, size + 1);
61    OUT_RING (chan, (size << 18) | mthd);
62 }
63
64 /* non-incremental */
65 static INLINE void
66 BEGIN_RING_NI(struct nouveau_channel *chan, uint32_t mthd, unsigned size)
67 {
68    WAIT_RING(chan, size + 1);
69    OUT_RING (chan, (0x2 << 29) | (size << 18) | mthd);
70 }
71
72 static INLINE int
73 OUT_RESRCh(struct nouveau_channel *chan, struct nv04_resource *res,
74            unsigned delta, unsigned flags)
75 {
76    return OUT_RELOCh(chan, res->bo, res->offset + delta, res->domain | flags);
77 }
78
79 static INLINE int
80 OUT_RESRCl(struct nouveau_channel *chan, struct nv04_resource *res,
81            unsigned delta, unsigned flags)
82 {
83    if (flags & NOUVEAU_BO_WR)
84       res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
85    return OUT_RELOCl(chan, res->bo, res->offset + delta, res->domain | flags);
86 }
87
88 static INLINE void
89 BIND_RING(struct nouveau_channel *chan, struct nouveau_grobj *gr, unsigned s)
90 {
91    struct nouveau_subchannel *subc = &gr->channel->subc[s];
92
93    assert(s < 8);
94    if (subc->gr) {
95       assert(subc->gr->bound != NOUVEAU_GROBJ_BOUND_EXPLICIT);
96       subc->gr->bound = NOUVEAU_GROBJ_UNBOUND;
97    }
98    subc->gr = gr;
99    subc->gr->subc = s;
100    subc->gr->bound = NOUVEAU_GROBJ_BOUND_EXPLICIT;
101
102    BEGIN_RING(chan, RING_GR(gr, 0x0000), 1);
103    OUT_RING  (chan, gr->handle);
104 }
105
106 #endif