1bf215546Sopenharmony_ci
2bf215546Sopenharmony_ci#ifndef __NV50_WINSYS_H__
3bf215546Sopenharmony_ci#define __NV50_WINSYS_H__
4bf215546Sopenharmony_ci
5bf215546Sopenharmony_ci#include <stdint.h>
6bf215546Sopenharmony_ci#include <unistd.h>
7bf215546Sopenharmony_ci
8bf215546Sopenharmony_ci#include "pipe/p_defines.h"
9bf215546Sopenharmony_ci
10bf215546Sopenharmony_ci#include "nouveau_winsys.h"
11bf215546Sopenharmony_ci#include "nouveau_buffer.h"
12bf215546Sopenharmony_ci
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ci#ifndef NV04_PFIFO_MAX_PACKET_LEN
15bf215546Sopenharmony_ci#define NV04_PFIFO_MAX_PACKET_LEN 2047
16bf215546Sopenharmony_ci#endif
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ci
19bf215546Sopenharmony_cistatic inline void
20bf215546Sopenharmony_cinv50_add_bufctx_resident_bo(struct nouveau_bufctx *bufctx, int bin,
21bf215546Sopenharmony_ci                            unsigned flags, struct nouveau_bo *bo)
22bf215546Sopenharmony_ci{
23bf215546Sopenharmony_ci   nouveau_bufctx_refn(bufctx, bin, bo, flags)->priv = NULL;
24bf215546Sopenharmony_ci}
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_cistatic inline void
27bf215546Sopenharmony_cinv50_add_bufctx_resident(struct nouveau_bufctx *bufctx, int bin,
28bf215546Sopenharmony_ci                         struct nv04_resource *res, unsigned flags)
29bf215546Sopenharmony_ci{
30bf215546Sopenharmony_ci   struct nouveau_bufref *ref =
31bf215546Sopenharmony_ci      nouveau_bufctx_refn(bufctx, bin, res->bo, flags | res->domain);
32bf215546Sopenharmony_ci   ref->priv = res;
33bf215546Sopenharmony_ci   ref->priv_data = flags;
34bf215546Sopenharmony_ci}
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_ci#define BCTX_REFN_bo(ctx, bin, fl, bo) \
37bf215546Sopenharmony_ci   nv50_add_bufctx_resident_bo(ctx, NV50_BIND_##bin, fl, bo);
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_ci#define BCTX_REFN(bctx, bin, res, acc) \
40bf215546Sopenharmony_ci   nv50_add_bufctx_resident(bctx, NV50_BIND_##bin, res, NOUVEAU_BO_##acc)
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_cistatic inline void
43bf215546Sopenharmony_ciPUSH_REFN(struct nouveau_pushbuf *push, struct nouveau_bo *bo, uint32_t flags)
44bf215546Sopenharmony_ci{
45bf215546Sopenharmony_ci   struct nouveau_pushbuf_refn ref = { bo, flags };
46bf215546Sopenharmony_ci   nouveau_pushbuf_refn(push, &ref, 1);
47bf215546Sopenharmony_ci}
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci#define SUBC_3D(m) 3, (m)
51bf215546Sopenharmony_ci#define NV50_3D(n) SUBC_3D(NV50_3D_##n)
52bf215546Sopenharmony_ci#define NV84_3D(n) SUBC_3D(NV84_3D_##n)
53bf215546Sopenharmony_ci#define NVA0_3D(n) SUBC_3D(NVA0_3D_##n)
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci#define SUBC_2D(m) 4, (m)
56bf215546Sopenharmony_ci#define NV50_2D(n) SUBC_2D(NV50_2D_##n)
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci#define SUBC_M2MF(m) 5, (m)
59bf215546Sopenharmony_ci#define NV50_M2MF(n) SUBC_M2MF(NV50_M2MF_##n)
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci#define SUBC_CP(m) 6, (m)
62bf215546Sopenharmony_ci#define NV50_CP(n) SUBC_CP(NV50_COMPUTE_##n)
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_cistatic inline uint32_t
66bf215546Sopenharmony_ciNV50_FIFO_PKHDR(int subc, int mthd, unsigned size)
67bf215546Sopenharmony_ci{
68bf215546Sopenharmony_ci   return 0x00000000 | (size << 18) | (subc << 13) | mthd;
69bf215546Sopenharmony_ci}
70bf215546Sopenharmony_ci
71bf215546Sopenharmony_cistatic inline uint32_t
72bf215546Sopenharmony_ciNV50_FIFO_PKHDR_NI(int subc, int mthd, unsigned size)
73bf215546Sopenharmony_ci{
74bf215546Sopenharmony_ci   return 0x40000000 | (size << 18) | (subc << 13) | mthd;
75bf215546Sopenharmony_ci}
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_cistatic inline uint32_t
78bf215546Sopenharmony_ciNV50_FIFO_PKHDR_L(int subc, int mthd)
79bf215546Sopenharmony_ci{
80bf215546Sopenharmony_ci   return 0x00030000 | (subc << 13) | mthd;
81bf215546Sopenharmony_ci}
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_cistatic inline uint32_t
85bf215546Sopenharmony_cinouveau_bo_memtype(const struct nouveau_bo *bo)
86bf215546Sopenharmony_ci{
87bf215546Sopenharmony_ci   return bo->config.nv50.memtype;
88bf215546Sopenharmony_ci}
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci
91bf215546Sopenharmony_cistatic inline void
92bf215546Sopenharmony_ciPUSH_DATAh(struct nouveau_pushbuf *push, uint64_t data)
93bf215546Sopenharmony_ci{
94bf215546Sopenharmony_ci   *push->cur++ = (uint32_t)(data >> 32);
95bf215546Sopenharmony_ci}
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_cistatic inline void
98bf215546Sopenharmony_ciBEGIN_NV04(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
99bf215546Sopenharmony_ci{
100bf215546Sopenharmony_ci#ifndef NV50_PUSH_EXPLICIT_SPACE_CHECKING
101bf215546Sopenharmony_ci   PUSH_SPACE(push, size + 1);
102bf215546Sopenharmony_ci#endif
103bf215546Sopenharmony_ci   PUSH_DATA (push, NV50_FIFO_PKHDR(subc, mthd, size));
104bf215546Sopenharmony_ci}
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_cistatic inline void
107bf215546Sopenharmony_ciBEGIN_NI04(struct nouveau_pushbuf *push, int subc, int mthd, unsigned size)
108bf215546Sopenharmony_ci{
109bf215546Sopenharmony_ci#ifndef NV50_PUSH_EXPLICIT_SPACE_CHECKING
110bf215546Sopenharmony_ci   PUSH_SPACE(push, size + 1);
111bf215546Sopenharmony_ci#endif
112bf215546Sopenharmony_ci   PUSH_DATA (push, NV50_FIFO_PKHDR_NI(subc, mthd, size));
113bf215546Sopenharmony_ci}
114bf215546Sopenharmony_ci
115bf215546Sopenharmony_ci/* long, non-incremental, nv50-only */
116bf215546Sopenharmony_cistatic inline void
117bf215546Sopenharmony_ciBEGIN_NL50(struct nouveau_pushbuf *push, int subc, int mthd, uint32_t size)
118bf215546Sopenharmony_ci{
119bf215546Sopenharmony_ci#ifndef NV50_PUSH_EXPLICIT_SPACE_CHECKING
120bf215546Sopenharmony_ci   PUSH_SPACE(push, 2);
121bf215546Sopenharmony_ci#endif
122bf215546Sopenharmony_ci   PUSH_DATA (push, NV50_FIFO_PKHDR_L(subc, mthd));
123bf215546Sopenharmony_ci   PUSH_DATA (push, size);
124bf215546Sopenharmony_ci}
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci#endif /* __NV50_WINSYS_H__ */
127