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
;
23 cp_out(struct nouveau_grctx
*ctx
, uint32_t inst
)
25 uint32_t *ctxprog
= ctx
->data
;
27 if (ctx
->mode
!= NOUVEAU_GRCTX_PROG
)
30 BUG_ON(ctx
->ctxprog_len
== ctx
->ctxprog_max
);
31 ctxprog
[ctx
->ctxprog_len
++] = inst
;
35 cp_lsr(struct nouveau_grctx
*ctx
, uint32_t val
)
37 cp_out(ctx
, CP_LOAD_SR
| val
);
41 cp_ctx(struct nouveau_grctx
*ctx
, uint32_t reg
, uint32_t length
)
43 ctx
->ctxprog_reg
= (reg
- 0x00400000) >> 2;
45 ctx
->ctxvals_base
= ctx
->ctxvals_pos
;
46 ctx
->ctxvals_pos
= ctx
->ctxvals_base
+ length
;
48 if (length
> (CP_CTX_COUNT
>> CP_CTX_COUNT_SHIFT
)) {
53 cp_out(ctx
, CP_CTX
| (length
<< CP_CTX_COUNT_SHIFT
) | ctx
->ctxprog_reg
);
57 cp_name(struct nouveau_grctx
*ctx
, int name
)
59 uint32_t *ctxprog
= ctx
->data
;
62 if (ctx
->mode
!= NOUVEAU_GRCTX_PROG
)
65 ctx
->ctxprog_label
[name
] = ctx
->ctxprog_len
;
66 for (i
= 0; i
< ctx
->ctxprog_len
; i
++) {
67 if ((ctxprog
[i
] & 0xfff00000) != 0xff400000)
69 if ((ctxprog
[i
] & CP_BRA_IP
) != ((name
) << CP_BRA_IP_SHIFT
))
71 ctxprog
[i
] = (ctxprog
[i
] & 0x00ff00ff) |
72 (ctx
->ctxprog_len
<< CP_BRA_IP_SHIFT
);
77 _cp_bra(struct nouveau_grctx
*ctx
, u32 mod
, int flag
, int state
, int name
)
82 ip
= ctx
->ctxprog_label
[name
] << CP_BRA_IP_SHIFT
;
84 ip
= 0xff000000 | (name
<< CP_BRA_IP_SHIFT
);
87 cp_out(ctx
, CP_BRA
| (mod
<< 18) | ip
| flag
|
88 (state
? 0 : CP_BRA_IF_CLEAR
));
90 #define cp_bra(c,f,s,n) _cp_bra((c), 0, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
92 #define cp_cal(c,f,s,n) _cp_bra((c), 1, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
93 #define cp_ret(c,f,s) _cp_bra((c), 2, CP_FLAG_##f, CP_FLAG_##f##_##s, 0)
97 _cp_wait(struct nouveau_grctx
*ctx
, int flag
, int state
)
99 cp_out(ctx
, CP_WAIT
| flag
| (state
? CP_WAIT_SET
: 0));
101 #define cp_wait(c,f,s) _cp_wait((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
104 _cp_set(struct nouveau_grctx
*ctx
, int flag
, int state
)
106 cp_out(ctx
, CP_SET
| flag
| (state
? CP_SET_1
: 0));
108 #define cp_set(c,f,s) _cp_set((c), CP_FLAG_##f, CP_FLAG_##f##_##s)
111 cp_pos(struct nouveau_grctx
*ctx
, int offset
)
113 ctx
->ctxvals_pos
= offset
;
114 ctx
->ctxvals_base
= ctx
->ctxvals_pos
;
116 cp_lsr(ctx
, ctx
->ctxvals_pos
);
117 cp_out(ctx
, CP_SET_CONTEXT_POINTER
);
121 gr_def(struct nouveau_grctx
*ctx
, uint32_t reg
, uint32_t val
)
123 if (ctx
->mode
!= NOUVEAU_GRCTX_VALS
)
126 reg
= (reg
- 0x00400000) / 4;
127 reg
= (reg
- ctx
->ctxprog_reg
) + ctx
->ctxvals_base
;
129 nv_wo32(ctx
->data
, reg
* 4, val
);