drm/nouveau: restructure source tree, split core from drm implementation
[linux-2.6-block.git] / drivers / gpu / drm / nouveau / core / engine / graph / ctx.h
CommitLineData
054b93e4
BS
1#ifndef __NOUVEAU_GRCTX_H__
2#define __NOUVEAU_GRCTX_H__
3
4struct nouveau_grctx {
5 struct drm_device *dev;
6
7 enum {
8 NOUVEAU_GRCTX_PROG,
9 NOUVEAU_GRCTX_VALS
10 } mode;
11 void *data;
12
13 uint32_t ctxprog_max;
14 uint32_t ctxprog_len;
15 uint32_t ctxprog_reg;
16 int ctxprog_label[32];
17 uint32_t ctxvals_pos;
18 uint32_t ctxvals_base;
19};
20
054b93e4
BS
21static inline void
22cp_out(struct nouveau_grctx *ctx, uint32_t inst)
23{
24 uint32_t *ctxprog = ctx->data;
25
26 if (ctx->mode != NOUVEAU_GRCTX_PROG)
27 return;
28
29 BUG_ON(ctx->ctxprog_len == ctx->ctxprog_max);
30 ctxprog[ctx->ctxprog_len++] = inst;
31}
32
33static inline void
34cp_lsr(struct nouveau_grctx *ctx, uint32_t val)
35{
36 cp_out(ctx, CP_LOAD_SR | val);
37}
38
39static inline void
40cp_ctx(struct nouveau_grctx *ctx, uint32_t reg, uint32_t length)
41{
42 ctx->ctxprog_reg = (reg - 0x00400000) >> 2;
43
44 ctx->ctxvals_base = ctx->ctxvals_pos;
45 ctx->ctxvals_pos = ctx->ctxvals_base + length;
46
47 if (length > (CP_CTX_COUNT >> CP_CTX_COUNT_SHIFT)) {
48 cp_lsr(ctx, length);
49 length = 0;
50 }
51
52 cp_out(ctx, CP_CTX | (length << CP_CTX_COUNT_SHIFT) | ctx->ctxprog_reg);
53}
54
55static inline void
56cp_name(struct nouveau_grctx *ctx, int name)
57{
58 uint32_t *ctxprog = ctx->data;
59 int i;
60
61 if (ctx->mode != NOUVEAU_GRCTX_PROG)
62 return;
63
64 ctx->ctxprog_label[name] = ctx->ctxprog_len;
65 for (i = 0; i < ctx->ctxprog_len; i++) {
66 if ((ctxprog[i] & 0xfff00000) != 0xff400000)
67 continue;
68 if ((ctxprog[i] & CP_BRA_IP) != ((name) << CP_BRA_IP_SHIFT))
69 continue;
70 ctxprog[i] = (ctxprog[i] & 0x00ff00ff) |
71 (ctx->ctxprog_len << CP_BRA_IP_SHIFT);
72 }
73}
74
75static inline void
76_cp_bra(struct nouveau_grctx *ctx, u32 mod, int flag, int state, int name)
77{
78 int ip = 0;
79
80 if (mod != 2) {
81 ip = ctx->ctxprog_label[name] << CP_BRA_IP_SHIFT;
82 if (ip == 0)
83 ip = 0xff000000 | (name << CP_BRA_IP_SHIFT);
84 }
85
86 cp_out(ctx, CP_BRA | (mod << 18) | ip | flag |
87 (state ? 0 : CP_BRA_IF_CLEAR));
88}
0b89a072 89#define cp_bra(c, f, s, n) _cp_bra((c), 0, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
0b89a072
EV
90#define cp_cal(c, f, s, n) _cp_bra((c), 1, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
91#define cp_ret(c, f, s) _cp_bra((c), 2, CP_FLAG_##f, CP_FLAG_##f##_##s, 0)
054b93e4
BS
92
93static inline void
94_cp_wait(struct nouveau_grctx *ctx, int flag, int state)
95{
96 cp_out(ctx, CP_WAIT | flag | (state ? CP_WAIT_SET : 0));
97}
0b89a072 98#define cp_wait(c, f, s) _cp_wait((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
054b93e4
BS
99
100static inline void
101_cp_set(struct nouveau_grctx *ctx, int flag, int state)
102{
103 cp_out(ctx, CP_SET | flag | (state ? CP_SET_1 : 0));
104}
0b89a072 105#define cp_set(c, f, s) _cp_set((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
054b93e4
BS
106
107static inline void
108cp_pos(struct nouveau_grctx *ctx, int offset)
109{
110 ctx->ctxvals_pos = offset;
111 ctx->ctxvals_base = ctx->ctxvals_pos;
112
113 cp_lsr(ctx, ctx->ctxvals_pos);
114 cp_out(ctx, CP_SET_CONTEXT_POINTER);
115}
116
117static inline void
118gr_def(struct nouveau_grctx *ctx, uint32_t reg, uint32_t val)
119{
120 if (ctx->mode != NOUVEAU_GRCTX_VALS)
121 return;
122
123 reg = (reg - 0x00400000) / 4;
124 reg = (reg - ctx->ctxprog_reg) + ctx->ctxvals_base;
125
b3beb167 126 nv_wo32(ctx->data, reg * 4, val);
054b93e4 127}
054b93e4
BS
128
129#endif