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