1 
2 #ifndef __NVC0_WINSYS_H__
3 #define __NVC0_WINSYS_H__
4 
5 #include <stdint.h>
6 #include <unistd.h>
7 
8 #include "pipe/p_defines.h"
9 
10 #include "nouveau/nouveau_winsys.h"
11 #include "nouveau/nouveau_buffer.h"
12 
13 #ifndef NV04_PFIFO_MAX_PACKET_LEN
14 #define NV04_PFIFO_MAX_PACKET_LEN 2047
15 #endif
16 
17 
18 static INLINE void
nv50_add_bufctx_resident_bo(struct nouveau_bufctx * bufctx,int bin,unsigned flags,struct nouveau_bo * bo)19 nv50_add_bufctx_resident_bo(struct nouveau_bufctx *bufctx, int bin,
20                             unsigned flags, struct nouveau_bo *bo)
21 {
22    nouveau_bufctx_refn(bufctx, bin, bo, flags)->priv = NULL;
23 }
24 
25 static INLINE void
nvc0_add_resident(struct nouveau_bufctx * bufctx,int bin,struct nv04_resource * res,unsigned flags)26 nvc0_add_resident(struct nouveau_bufctx *bufctx, int bin,
27                   struct nv04_resource *res, unsigned flags)
28 {
29    struct nouveau_bufref *ref =
30       nouveau_bufctx_refn(bufctx, bin, res->bo, flags | res->domain);
31    ref->priv = res;
32    ref->priv_data = flags;
33 }
34 
35 #define BCTX_REFN_bo(ctx, bin, fl, bo) \
36    nv50_add_bufctx_resident_bo(ctx, NVC0_BIND_##bin, fl, bo);
37 
38 #define BCTX_REFN(bctx, bin, res, acc) \
39    nvc0_add_resident(bctx, NVC0_BIND_##bin, res, NOUVEAU_BO_##acc)
40 
41 static INLINE void
PUSH_REFN(struct nouveau_pushbuf * push,struct nouveau_bo * bo,uint32_t flags)42 PUSH_REFN(struct nouveau_pushbuf *push, struct nouveau_bo *bo, uint32_t flags)
43 {
44    struct nouveau_pushbuf_refn ref = { bo, flags };
45    nouveau_pushbuf_refn(push, &ref, 1);
46 }
47 
48 
49 #define SUBC_3D(m) 0, (m)
50 #define NVC0_3D(n) SUBC_3D(NVC0_3D_##n)
51 #define NVE4_3D(n) SUBC_3D(NVE4_3D_##n)
52 
53 #define SUBC_COMPUTE(m) 1, (m)
54 #define NVC0_COMPUTE(n) SUBC_COMPUTE(NVC0_COMPUTE_##n)
55 #define NVE4_COMPUTE(n) SUBC_COMPUTE(NVE4_COMPUTE_##n)
56 
57 #define SUBC_M2MF(m) 2, (m)
58 #define SUBC_P2MF(m) 2, (m)
59 #define NVC0_M2MF(n) SUBC_M2MF(NVC0_M2MF_##n)
60 #define NVE4_P2MF(n) SUBC_P2MF(NVE4_P2MF_##n)
61 
62 #define SUBC_2D(m) 3, (m)
63 #define NVC0_2D(n) SUBC_2D(NVC0_2D_##n)
64 
65 #define SUBC_COPY(m) 4, (m)
66 #define NVE4_COPY(m) SUBC_COPY(NVE4_COPY_##n)
67 
68 static INLINE uint32_t
NVC0_FIFO_PKHDR_SQ(int subc,int mthd,unsigned size)69 NVC0_FIFO_PKHDR_SQ(int subc, int mthd, unsigned size)
70 {
71    return 0x20000000 | (size << 16) | (subc << 13) | (mthd >> 2);
72 }
73 
74 static INLINE uint32_t
NVC0_FIFO_PKHDR_NI(int subc,int mthd,unsigned size)75 NVC0_FIFO_PKHDR_NI(int subc, int mthd, unsigned size)
76 {
77    return 0x60000000 | (size << 16) | (subc << 13) | (mthd >> 2);
78 }
79 
80 static INLINE uint32_t
NVC0_FIFO_PKHDR_IL(int subc,int mthd,uint8_t data)81 NVC0_FIFO_PKHDR_IL(int subc, int mthd, uint8_t data)
82 {
83    return 0x80000000 | (data << 16) | (subc << 13) | (mthd >> 2);
84 }
85 
86 static INLINE uint32_t
NVC0_FIFO_PKHDR_1I(int subc,int mthd,unsigned size)87 NVC0_FIFO_PKHDR_1I(int subc, int mthd, unsigned size)
88 {
89    return 0xa0000000 | (size << 16) | (subc << 13) | (mthd >> 2);
90 }
91 
92 
93 static INLINE uint8_t
nouveau_bo_memtype(const struct nouveau_bo * bo)94 nouveau_bo_memtype(const struct nouveau_bo *bo)
95 {
96    return bo->config.nvc0.memtype;
97 }
98 
99 
100 static INLINE void
PUSH_DATAh(struct nouveau_pushbuf * push,uint64_t data)101 PUSH_DATAh(struct nouveau_pushbuf *push, uint64_t data)
102 {
103    *push->cur++ = (uint32_t)(data >> 32);
104 }
105 
106 static INLINE void
BEGIN_NVC0(struct nouveau_pushbuf * push,int subc,int mthd,unsigned size)107 BEGIN_NVC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
108 {
109 #ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
110    PUSH_SPACE(push, size + 1);
111 #endif
112    PUSH_DATA (push, NVC0_FIFO_PKHDR_SQ(subc, mthd, size));
113 }
114 
115 static INLINE void
BEGIN_NIC0(struct nouveau_pushbuf * push,int subc,int mthd,unsigned size)116 BEGIN_NIC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
117 {
118 #ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
119    PUSH_SPACE(push, size + 1);
120 #endif
121    PUSH_DATA (push, NVC0_FIFO_PKHDR_NI(subc, mthd, size));
122 }
123 
124 static INLINE void
BEGIN_1IC0(struct nouveau_pushbuf * push,int subc,int mthd,unsigned size)125 BEGIN_1IC0(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
126 {
127 #ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
128    PUSH_SPACE(push, size + 1);
129 #endif
130    PUSH_DATA (push, NVC0_FIFO_PKHDR_1I(subc, mthd, size));
131 }
132 
133 static INLINE void
IMMED_NVC0(struct nouveau_pushbuf * push,int subc,int mthd,uint8_t data)134 IMMED_NVC0(struct nouveau_pushbuf *push, int subc, int mthd, uint8_t data)
135 {
136 #ifndef NVC0_PUSH_EXPLICIT_SPACE_CHECKING
137    PUSH_SPACE(push, 1);
138 #endif
139    PUSH_DATA (push, NVC0_FIFO_PKHDR_IL(subc, mthd, data));
140 }
141 
142 #endif /* __NVC0_WINSYS_H__ */
143