1 #ifndef __NVKM_FBRAM_FUC_H__
2 #define __NVKM_FBRAM_FUC_H__
3 #include <subdev/pmu.h>
6 struct nvkm_memx
*memx
;
15 u32 stride
; /* in bytes */
20 static inline struct ramfuc_reg
21 ramfuc_stride(u32 addr
, u32 stride
, u32 mask
)
23 return (struct ramfuc_reg
) {
32 static inline struct ramfuc_reg
33 ramfuc_reg2(u32 addr1
, u32 addr2
)
35 return (struct ramfuc_reg
) {
38 .stride
= addr2
- addr1
,
44 static noinline
struct ramfuc_reg
47 return (struct ramfuc_reg
) {
57 ramfuc_init(struct ramfuc
*ram
, struct nvkm_fb
*pfb
)
59 struct nvkm_pmu
*pmu
= nvkm_pmu(pfb
);
62 ret
= nvkm_memx_init(pmu
, &ram
->memx
);
72 ramfuc_exec(struct ramfuc
*ram
, bool exec
)
76 ret
= nvkm_memx_fini(&ram
->memx
, exec
);
83 ramfuc_rd32(struct ramfuc
*ram
, struct ramfuc_reg
*reg
)
85 if (reg
->sequence
!= ram
->sequence
)
86 reg
->data
= nv_rd32(ram
->pfb
, reg
->addr
);
91 ramfuc_wr32(struct ramfuc
*ram
, struct ramfuc_reg
*reg
, u32 data
)
93 unsigned int mask
, off
= 0;
95 reg
->sequence
= ram
->sequence
;
98 for (mask
= reg
->mask
; mask
> 0; mask
= (mask
& ~1) >> 1) {
100 nvkm_memx_wr32(ram
->memx
, reg
->addr
+off
, reg
->data
);
106 ramfuc_nuke(struct ramfuc
*ram
, struct ramfuc_reg
*reg
)
112 ramfuc_mask(struct ramfuc
*ram
, struct ramfuc_reg
*reg
, u32 mask
, u32 data
)
114 u32 temp
= ramfuc_rd32(ram
, reg
);
115 if (temp
!= ((temp
& ~mask
) | data
) || reg
->force
) {
116 ramfuc_wr32(ram
, reg
, (temp
& ~mask
) | data
);
123 ramfuc_wait(struct ramfuc
*ram
, u32 addr
, u32 mask
, u32 data
, u32 nsec
)
125 nvkm_memx_wait(ram
->memx
, addr
, mask
, data
, nsec
);
129 ramfuc_nsec(struct ramfuc
*ram
, u32 nsec
)
131 nvkm_memx_nsec(ram
->memx
, nsec
);
135 ramfuc_wait_vblank(struct ramfuc
*ram
)
137 nvkm_memx_wait_vblank(ram
->memx
);
141 ramfuc_train(struct ramfuc
*ram
)
143 nvkm_memx_train(ram
->memx
);
147 ramfuc_train_result(struct nvkm_fb
*pfb
, u32
*result
, u32 rsize
)
149 struct nvkm_pmu
*pmu
= nvkm_pmu(pfb
);
151 return nvkm_memx_train_result(pmu
, result
, rsize
);
155 ramfuc_block(struct ramfuc
*ram
)
157 nvkm_memx_block(ram
->memx
);
161 ramfuc_unblock(struct ramfuc
*ram
)
163 nvkm_memx_unblock(ram
->memx
);
166 #define ram_init(s,p) ramfuc_init(&(s)->base, (p))
167 #define ram_exec(s,e) ramfuc_exec(&(s)->base, (e))
168 #define ram_have(s,r) ((s)->r_##r.addr != 0x000000)
169 #define ram_rd32(s,r) ramfuc_rd32(&(s)->base, &(s)->r_##r)
170 #define ram_wr32(s,r,d) ramfuc_wr32(&(s)->base, &(s)->r_##r, (d))
171 #define ram_nuke(s,r) ramfuc_nuke(&(s)->base, &(s)->r_##r)
172 #define ram_mask(s,r,m,d) ramfuc_mask(&(s)->base, &(s)->r_##r, (m), (d))
173 #define ram_wait(s,r,m,d,n) ramfuc_wait(&(s)->base, (r), (m), (d), (n))
174 #define ram_nsec(s,n) ramfuc_nsec(&(s)->base, (n))
175 #define ram_wait_vblank(s) ramfuc_wait_vblank(&(s)->base)
176 #define ram_train(s) ramfuc_train(&(s)->base)
177 #define ram_train_result(s,r,l) ramfuc_train_result((s), (r), (l))
178 #define ram_block(s) ramfuc_block(&(s)->base)
179 #define ram_unblock(s) ramfuc_unblock(&(s)->base)