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 <core/memory.h>
27
28void
29nvkm_ltc_tags_clear(struct nvkm_device *device, u32 first, u32 count)
30{
31 struct nvkm_ltc *ltc = device->ltc;
32 const u32 limit = first + count - 1;
33
34 BUG_ON((first > limit) || (limit >= ltc->num_tags));
35
36 mutex_lock(<c->mutex);
37 ltc->func->cbc_clear(ltc, first, limit);
38 ltc->func->cbc_wait(ltc);
39 mutex_unlock(<c->mutex);
40}
41
42int
43nvkm_ltc_zbc_color_get(struct nvkm_ltc *ltc, int index, const u32 color[4])
44{
45 memcpy(ltc->zbc_color[index], color, sizeof(ltc->zbc_color[index]));
46 ltc->func->zbc_clear_color(ltc, index, color);
47 return index;
48}
49
50int
51nvkm_ltc_zbc_depth_get(struct nvkm_ltc *ltc, int index, const u32 depth)
52{
53 ltc->zbc_depth[index] = depth;
54 ltc->func->zbc_clear_depth(ltc, index, depth);
55 return index;
56}
57
58int
59nvkm_ltc_zbc_stencil_get(struct nvkm_ltc *ltc, int index, const u32 stencil)
60{
61 ltc->zbc_stencil[index] = stencil;
62 ltc->func->zbc_clear_stencil(ltc, index, stencil);
63 return index;
64}
65
66void
67nvkm_ltc_invalidate(struct nvkm_ltc *ltc)
68{
69 if (ltc->func->invalidate)
70 ltc->func->invalidate(ltc);
71}
72
73void
74nvkm_ltc_flush(struct nvkm_ltc *ltc)
75{
76 if (ltc->func->flush)
77 ltc->func->flush(ltc);
78}
79
80static void
81nvkm_ltc_intr(struct nvkm_subdev *subdev)
82{
83 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
84 ltc->func->intr(ltc);
85}
86
87static int
88nvkm_ltc_oneinit(struct nvkm_subdev *subdev)
89{
90 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
91 return ltc->func->oneinit(ltc);
92}
93
94static int
95nvkm_ltc_init(struct nvkm_subdev *subdev)
96{
97 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
98 int i;
99
100 for (i = ltc->zbc_min; i <= ltc->zbc_max; i++) {
101 ltc->func->zbc_clear_color(ltc, i, ltc->zbc_color[i]);
102 ltc->func->zbc_clear_depth(ltc, i, ltc->zbc_depth[i]);
103 if (ltc->func->zbc_clear_stencil)
104 ltc->func->zbc_clear_stencil(ltc, i, ltc->zbc_stencil[i]);
105 }
106
107 ltc->func->init(ltc);
108 return 0;
109}
110
111static void *
112nvkm_ltc_dtor(struct nvkm_subdev *subdev)
113{
114 struct nvkm_ltc *ltc = nvkm_ltc(subdev);
115 nvkm_memory_unref(<c->tag_ram);
116 mutex_destroy(<c->mutex);
117 return ltc;
118}
119
120static const struct nvkm_subdev_func
121nvkm_ltc = {
122 .dtor = nvkm_ltc_dtor,
123 .oneinit = nvkm_ltc_oneinit,
124 .init = nvkm_ltc_init,
125 .intr = nvkm_ltc_intr,
126};
127
128int
129nvkm_ltc_new_(const struct nvkm_ltc_func *func, struct nvkm_device *device,
130 enum nvkm_subdev_type type, int inst, struct nvkm_ltc **pltc)
131{
132 struct nvkm_ltc *ltc;
133
134 if (!(ltc = *pltc = kzalloc(sizeof(*ltc), GFP_KERNEL)))
135 return -ENOMEM;
136
137 nvkm_subdev_ctor(&nvkm_ltc, device, type, inst, <c->subdev);
138 ltc->func = func;
139 mutex_init(<c->mutex);
140 ltc->zbc_min = 1;
141 ltc->zbc_max = min(func->zbc, NVKM_LTC_MAX_ZBC_CNT) - 1;
142 return 0;
143}
144