Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / gpu / drm / nouveau / nvkm / engine / gr / ctxnv40.h
blob7917567ade3a72cd86a1da8a4b1933ae1507f1ef
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_GRCTX_H__
3 #define __NVKM_GRCTX_H__
4 #include <core/gpuobj.h>
6 struct nvkm_grctx {
7 struct nvkm_device *device;
9 enum {
10 NVKM_GRCTX_PROG,
11 NVKM_GRCTX_VALS
12 } mode;
13 u32 *ucode;
14 struct nvkm_gpuobj *data;
16 u32 ctxprog_max;
17 u32 ctxprog_len;
18 u32 ctxprog_reg;
19 int ctxprog_label[32];
20 u32 ctxvals_pos;
21 u32 ctxvals_base;
24 static inline void
25 cp_out(struct nvkm_grctx *ctx, u32 inst)
27 u32 *ctxprog = ctx->ucode;
29 if (ctx->mode != NVKM_GRCTX_PROG)
30 return;
32 BUG_ON(ctx->ctxprog_len == ctx->ctxprog_max);
33 ctxprog[ctx->ctxprog_len++] = inst;
36 static inline void
37 cp_lsr(struct nvkm_grctx *ctx, u32 val)
39 cp_out(ctx, CP_LOAD_SR | val);
42 static inline void
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)) {
51 cp_lsr(ctx, length);
52 length = 0;
55 cp_out(ctx, CP_CTX | (length << CP_CTX_COUNT_SHIFT) | ctx->ctxprog_reg);
58 static inline void
59 cp_name(struct nvkm_grctx *ctx, int name)
61 u32 *ctxprog = ctx->ucode;
62 int i;
64 if (ctx->mode != NVKM_GRCTX_PROG)
65 return;
67 ctx->ctxprog_label[name] = ctx->ctxprog_len;
68 for (i = 0; i < ctx->ctxprog_len; i++) {
69 if ((ctxprog[i] & 0xfff00000) != 0xff400000)
70 continue;
71 if ((ctxprog[i] & CP_BRA_IP) != ((name) << CP_BRA_IP_SHIFT))
72 continue;
73 ctxprog[i] = (ctxprog[i] & 0x00ff00ff) |
74 (ctx->ctxprog_len << CP_BRA_IP_SHIFT);
78 static inline void
79 _cp_bra(struct nvkm_grctx *ctx, u32 mod, int flag, int state, int name)
81 int ip = 0;
83 if (mod != 2) {
84 ip = ctx->ctxprog_label[name] << CP_BRA_IP_SHIFT;
85 if (ip == 0)
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)
96 static inline void
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)
103 static inline void
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)
110 static inline void
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);
120 static inline void
121 gr_def(struct nvkm_grctx *ctx, u32 reg, u32 val)
123 if (ctx->mode != NVKM_GRCTX_VALS)
124 return;
126 reg = (reg - 0x00400000) / 4;
127 reg = (reg - ctx->ctxprog_reg) + ctx->ctxvals_base;
129 nvkm_wo32(ctx->data, reg * 4, val);
131 #endif