1 #ifndef __NOUVEAU_GRCTX_H__
2 #define __NOUVEAU_GRCTX_H__
5 struct drm_device
*dev
;
16 int ctxprog_label
[32];
18 uint32_t ctxvals_base
;
22 cp_out(struct nouveau_grctx
*ctx
, uint32_t inst
)
24 uint32_t *ctxprog
= ctx
->data
;
26 if (ctx
->mode
!= NOUVEAU_GRCTX_PROG
)
29 BUG_ON(ctx
->ctxprog_len
== ctx
->ctxprog_max
);
30 ctxprog
[ctx
->ctxprog_len
++] = inst
;
34 cp_lsr(struct nouveau_grctx
*ctx
, uint32_t val
)
36 cp_out(ctx
, CP_LOAD_SR
| val
);
40 cp_ctx(struct nouveau_grctx
*ctx
, uint32_t reg
, uint32_t length
)
42 ctx
->ctxprog_reg
= (reg
- 0x00400000) >> 2;
44 ctx
->ctxvals_base
= ctx
->ctxvals_pos
;
45 ctx
->ctxvals_pos
= ctx
->ctxvals_base
+ length
;
47 if (length
> (CP_CTX_COUNT
>> CP_CTX_COUNT_SHIFT
)) {
52 cp_out(ctx
, CP_CTX
| (length
<< CP_CTX_COUNT_SHIFT
) | ctx
->ctxprog_reg
);
56 cp_name(struct nouveau_grctx
*ctx
, int name
)
58 uint32_t *ctxprog
= ctx
->data
;
61 if (ctx
->mode
!= NOUVEAU_GRCTX_PROG
)
64 ctx
->ctxprog_label
[name
] = ctx
->ctxprog_len
;
65 for (i
= 0; i
< ctx
->ctxprog_len
; i
++) {
66 if ((ctxprog
[i
] & 0xfff00000) != 0xff400000)
68 if ((ctxprog
[i
] & CP_BRA_IP
) != ((name
) << CP_BRA_IP_SHIFT
))
70 ctxprog
[i
] = (ctxprog
[i
] & 0x00ff00ff) |
71 (ctx
->ctxprog_len
<< CP_BRA_IP_SHIFT
);
76 _cp_bra(struct nouveau_grctx
*ctx
, u32 mod
, int flag
, int state
, int name
)
81 ip
= ctx
->ctxprog_label
[name
] << CP_BRA_IP_SHIFT
;
83 ip
= 0xff000000 | (name
<< CP_BRA_IP_SHIFT
);
86 cp_out(ctx
, CP_BRA
| (mod
<< 18) | ip
| flag
|
87 (state
? 0 : CP_BRA_IF_CLEAR
));
89 #define cp_bra(c, f, s, n) _cp_bra((c), 0, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
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)
94 _cp_wait(struct nouveau_grctx
*ctx
, int flag
, int state
)
96 cp_out(ctx
, CP_WAIT
| flag
| (state
? CP_WAIT_SET
: 0));
98 #define cp_wait(c, f, s) _cp_wait((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
101 _cp_set(struct nouveau_grctx
*ctx
, int flag
, int state
)
103 cp_out(ctx
, CP_SET
| flag
| (state
? CP_SET_1
: 0));
105 #define cp_set(c, f, s) _cp_set((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
108 cp_pos(struct nouveau_grctx
*ctx
, int offset
)
110 ctx
->ctxvals_pos
= offset
;
111 ctx
->ctxvals_base
= ctx
->ctxvals_pos
;
113 cp_lsr(ctx
, ctx
->ctxvals_pos
);
114 cp_out(ctx
, CP_SET_CONTEXT_POINTER
);
118 gr_def(struct nouveau_grctx
*ctx
, uint32_t reg
, uint32_t val
)
120 if (ctx
->mode
!= NOUVEAU_GRCTX_VALS
)
123 reg
= (reg
- 0x00400000) / 4;
124 reg
= (reg
- ctx
->ctxprog_reg
) + ctx
->ctxvals_base
;
126 nv_wo32(ctx
->data
, reg
* 4, val
);