1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "priv.h"
25
26#include <subdev/fb.h>
27
28int
29nvkm_ltc_tags_alloc(struct nvkm_ltc *ltc, u32 n, struct nvkm_mm_node **pnode)
30{
31 int ret = nvkm_mm_head(<c->tags, 0, 1, n, n, 1, pnode);
32 if (ret)
33 *pnode = NULL;
34 return ret;
35}
36
37void
38nvkm_ltc_tags_free(struct nvkm_ltc *ltc, struct nvkm_mm_node **pnode)
39{
40 nvkm_mm_free(<c->tags, pnode);
41}
42
43void
44nvkm_ltc_tags_clear(struct nvkm_ltc *ltc, u32 first, u32 count)
45{
46 const u32 limit = first + count - 1;
47
48 BUG_ON((first > limit) || (limit >= ltc->num_tags));
49
50 ltc->func->cbc_clear(ltc, first, limit);
51 ltc->func->cbc_wait(ltc);
52}
53
54int
55nvkm_ltc_zbc_color_get(struct nvkm_ltc *ltc, int index, const u32 color[4])
56{
57 memcpy(ltc->zbc_color[index], color, sizeof(ltc->zbc_color[index]));
58 ltc->func->zbc_clear_color(ltc, index, color);
59 return index;
60}
61
62int
63nvkm_ltc_zbc_depth_get(struct nvkm_ltc *ltc, int index, const u32 depth)
64{
65 ltc->zbc_depth[index] = depth;
66 ltc->func->zbc_clear_depth(ltc, index, depth);
67 return index;
68}
69
70void
71nvkm_ltc_invalidate(struct nvkm_ltc *ltc)
72{
73 if (ltc->func->invalidate)
74 ltc->func->invalidate(ltc);
75}
76
77void
78nvkm_ltc_flush(struct nvkm_ltc *ltc)
79{
80 if (ltc->func->flush)
81 ltc->func->flush(ltc);
82}
83
84static void
85nvkm_ltc_intr(struct nvkm_subdev *subdev)
86{
87 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
88 ltc->func->intr(ltc);
89}
90
91static int
92nvkm_ltc_oneinit(struct nvkm_subdev *subdev)
93{
94 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
95 return ltc->func->oneinit(ltc);
96}
97
98static int
99nvkm_ltc_init(struct nvkm_subdev *subdev)
100{
101 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
102 int i;
103
104 for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) {
105 ltc->func->zbc_clear_color(ltc, i, ltc->zbc_color[i]);
106 ltc->func->zbc_clear_depth(ltc, i, ltc->zbc_depth[i]);
107 }
108
109 ltc->func->init(ltc);
110 return 0;
111}
112
113static void *
114nvkm_ltc_dtor(struct nvkm_subdev *subdev)
115{
116 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
117 struct nvkm_ram *ram = ltc->subdev.device->fb->ram;
118 nvkm_mm_fini(<c->tags);
119 if (ram)
120 nvkm_mm_free(&ram->vram, <c->tag_ram);
121 return ltc;
122}
123
124static const struct nvkm_subdev_func
125nvkm_ltc = {
126 .dtor = nvkm_ltc_dtor,
127 .oneinit = nvkm_ltc_oneinit,
128 .init = nvkm_ltc_init,
129 .intr = nvkm_ltc_intr,
130};
131
132int
133nvkm_ltc_new_(const struct nvkm_ltc_func *func, struct nvkm_device *device,
134 int index, struct nvkm_ltc **pltc)
135{
136 struct nvkm_ltc *ltc;
137
138 if (!(ltc = *pltc = kzalloc(sizeof(*ltc), GFP_KERNEL)))
139 return -ENOMEM;
140
141 nvkm_subdev_ctor(&nvkm_ltc, device, index, 0, <c->subdev);
142 ltc->func = func;
143 ltc->zbc_min = 1;
144 ltc->zbc_max = min(func->zbc, NVKM_LTC_MAX_ZBC_CNT) - 1;
145 return 0;
146}
147