1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_GRCTX_H__
3 #define __NVKM_GRCTX_H__
4 #include <core/gpuobj.h>
7 struct nvkm_device
*device
;
14 struct nvkm_gpuobj
*data
;
19 int ctxprog_label
[32];
25 cp_out(struct nvkm_grctx
*ctx
, u32 inst
)
27 u32
*ctxprog
= ctx
->ucode
;
29 if (ctx
->mode
!= NVKM_GRCTX_PROG
)
32 BUG_ON(ctx
->ctxprog_len
== ctx
->ctxprog_max
);
33 ctxprog
[ctx
->ctxprog_len
++] = inst
;
37 cp_lsr(struct nvkm_grctx
*ctx
, u32 val
)
39 cp_out(ctx
, CP_LOAD_SR
| val
);
43 cp_ctx(struct nvkm_grctx
*ctx
, u32 reg
, u32 length
)
45 ctx
->ctxprog_reg
= (reg
- 0x00400000) >> 2;
47 ctx
->ctxvals_base
= ctx
->ctxvals_pos
;
48 ctx
->ctxvals_pos
= ctx
->ctxvals_base
+ length
;
50 if (length
> (CP_CTX_COUNT
>> CP_CTX_COUNT_SHIFT
)) {
55 cp_out(ctx
, CP_CTX
| (length
<< CP_CTX_COUNT_SHIFT
) | ctx
->ctxprog_reg
);
59 cp_name(struct nvkm_grctx
*ctx
, int name
)
61 u32
*ctxprog
= ctx
->ucode
;
64 if (ctx
->mode
!= NVKM_GRCTX_PROG
)
67 ctx
->ctxprog_label
[name
] = ctx
->ctxprog_len
;
68 for (i
= 0; i
< ctx
->ctxprog_len
; i
++) {
69 if ((ctxprog
[i
] & 0xfff00000) != 0xff400000)
71 if ((ctxprog
[i
] & CP_BRA_IP
) != ((name
) << CP_BRA_IP_SHIFT
))
73 ctxprog
[i
] = (ctxprog
[i
] & 0x00ff00ff) |
74 (ctx
->ctxprog_len
<< CP_BRA_IP_SHIFT
);
79 _cp_bra(struct nvkm_grctx
*ctx
, u32 mod
, int flag
, int state
, int name
)
84 ip
= ctx
->ctxprog_label
[name
] << CP_BRA_IP_SHIFT
;
86 ip
= 0xff000000 | (name
<< CP_BRA_IP_SHIFT
);
89 cp_out(ctx
, CP_BRA
| (mod
<< 18) | ip
| flag
|
90 (state
? 0 : CP_BRA_IF_CLEAR
));
92 #define cp_bra(c, f, s, n) _cp_bra((c), 0, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
93 #define cp_cal(c, f, s, n) _cp_bra((c), 1, CP_FLAG_##f, CP_FLAG_##f##_##s, n)
94 #define cp_ret(c, f, s) _cp_bra((c), 2, CP_FLAG_##f, CP_FLAG_##f##_##s, 0)
97 _cp_wait(struct nvkm_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 nvkm_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 nvkm_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 nvkm_grctx
*ctx
, u32 reg
, u32 val
)
123 if (ctx
->mode
!= NVKM_GRCTX_VALS
)
126 reg
= (reg
- 0x00400000) / 4;
127 reg
= (reg
- ctx
->ctxprog_reg
) + ctx
->ctxvals_base
;
129 nvkm_wo32(ctx
->data
, reg
* 4, val
);