]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/gpu/drm/nouveau/nvkm/subdev/ltc/gf100.c
drm/nouveau/imem: switch to device pri macros
[mirror_ubuntu-bionic-kernel.git] / drivers / gpu / drm / nouveau / nvkm / subdev / ltc / gf100.c
CommitLineData
861d2107
BS
1/*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
2799bba6 24#include "priv.h"
861d2107 25
2799bba6 26#include <core/enum.h>
e30441ad
CB
27#include <subdev/fb.h>
28#include <subdev/timer.h>
861d2107 29
95484b57 30void
c7750cfb 31gf100_ltc_cbc_clear(struct nvkm_ltc_priv *ltc, u32 start, u32 limit)
95484b57 32{
c7750cfb
BS
33 nv_wr32(ltc, 0x17e8cc, start);
34 nv_wr32(ltc, 0x17e8d0, limit);
35 nv_wr32(ltc, 0x17e8c8, 0x00000004);
95484b57
BS
36}
37
38void
c7750cfb 39gf100_ltc_cbc_wait(struct nvkm_ltc_priv *ltc)
95484b57
BS
40{
41 int c, s;
c7750cfb
BS
42 for (c = 0; c < ltc->ltc_nr; c++) {
43 for (s = 0; s < ltc->lts_nr; s++)
44 nv_wait(ltc, 0x1410c8 + c * 0x2000 + s * 0x400, ~0, 0);
95484b57
BS
45 }
46}
861d2107 47
f38fdb6a 48void
c7750cfb 49gf100_ltc_zbc_clear_color(struct nvkm_ltc_priv *ltc, int i, const u32 color[4])
f38fdb6a 50{
c7750cfb
BS
51 nv_mask(ltc, 0x17ea44, 0x0000000f, i);
52 nv_wr32(ltc, 0x17ea48, color[0]);
53 nv_wr32(ltc, 0x17ea4c, color[1]);
54 nv_wr32(ltc, 0x17ea50, color[2]);
55 nv_wr32(ltc, 0x17ea54, color[3]);
f38fdb6a
BS
56}
57
58void
c7750cfb 59gf100_ltc_zbc_clear_depth(struct nvkm_ltc_priv *ltc, int i, const u32 depth)
f38fdb6a 60{
c7750cfb
BS
61 nv_mask(ltc, 0x17ea44, 0x0000000f, i);
62 nv_wr32(ltc, 0x17ea58, depth);
f38fdb6a
BS
63}
64
2799bba6 65static const struct nvkm_bitfield
a1fc50b4
BS
66gf100_ltc_lts_intr_name[] = {
67 { 0x00000001, "IDLE_ERROR_IQ" },
68 { 0x00000002, "IDLE_ERROR_CBC" },
69 { 0x00000004, "IDLE_ERROR_TSTG" },
70 { 0x00000008, "IDLE_ERROR_DSTG" },
71 { 0x00000010, "EVICTED_CB" },
72 { 0x00000020, "ILLEGAL_COMPSTAT" },
73 { 0x00000040, "BLOCKLINEAR_CB" },
74 { 0x00000100, "ECC_SEC_ERROR" },
75 { 0x00000200, "ECC_DED_ERROR" },
76 { 0x00000400, "DEBUG" },
77 { 0x00000800, "ATOMIC_TO_Z" },
78 { 0x00001000, "ILLEGAL_ATOMIC" },
79 { 0x00002000, "BLKACTIVITY_ERR" },
80 {}
81};
82
861d2107 83static void
c7750cfb 84gf100_ltc_lts_intr(struct nvkm_ltc_priv *ltc, int c, int s)
861d2107 85{
c7750cfb
BS
86 u32 base = 0x141000 + (c * 0x2000) + (s * 0x400);
87 u32 intr = nv_rd32(ltc, base + 0x020);
a1fc50b4 88 u32 stat = intr & 0x0000ffff;
861d2107
BS
89
90 if (stat) {
c7750cfb 91 nv_info(ltc, "LTC%d_LTS%d:", c, s);
2799bba6 92 nvkm_bitfield_print(gf100_ltc_lts_intr_name, stat);
a1fc50b4 93 pr_cont("\n");
861d2107 94 }
a1fc50b4 95
c7750cfb 96 nv_wr32(ltc, base + 0x020, intr);
861d2107
BS
97}
98
95484b57 99void
2799bba6 100gf100_ltc_intr(struct nvkm_subdev *subdev)
861d2107 101{
c7750cfb 102 struct nvkm_ltc_priv *ltc = (void *)subdev;
f6bad8ab
BS
103 u32 mask;
104
c7750cfb 105 mask = nv_rd32(ltc, 0x00017c);
f6bad8ab 106 while (mask) {
c7750cfb
BS
107 u32 s, c = __ffs(mask);
108 for (s = 0; s < ltc->lts_nr; s++)
109 gf100_ltc_lts_intr(ltc, c, s);
110 mask &= ~(1 << c);
861d2107 111 }
861d2107
BS
112}
113
95484b57 114static int
2799bba6 115gf100_ltc_init(struct nvkm_object *object)
e30441ad 116{
c7750cfb
BS
117 struct nvkm_ltc_priv *ltc = (void *)object;
118 u32 lpg128 = !(nv_rd32(ltc, 0x100c80) & 0x00000001);
e30441ad
CB
119 int ret;
120
c7750cfb 121 ret = nvkm_ltc_init(ltc);
e30441ad 122 if (ret)
95484b57 123 return ret;
e30441ad 124
c7750cfb
BS
125 nv_mask(ltc, 0x17e820, 0x00100000, 0x00000000); /* INTR_EN &= ~0x10 */
126 nv_wr32(ltc, 0x17e8d8, ltc->ltc_nr);
127 nv_wr32(ltc, 0x17e8d4, ltc->tag_base);
128 nv_mask(ltc, 0x17e8c0, 0x00000002, lpg128 ? 0x00000002 : 0x00000000);
95484b57 129 return 0;
e30441ad
CB
130}
131
f6bad8ab 132void
2799bba6 133gf100_ltc_dtor(struct nvkm_object *object)
e30441ad 134{
b1e4553c 135 struct nvkm_fb *fb = nvkm_fb(object);
c7750cfb 136 struct nvkm_ltc_priv *ltc = (void *)object;
e30441ad 137
c7750cfb 138 nvkm_mm_fini(&ltc->tags);
b1e4553c 139 if (fb->ram)
c7750cfb 140 nvkm_mm_free(&fb->vram, &ltc->tag_ram);
e30441ad 141
c7750cfb 142 nvkm_ltc_destroy(ltc);
e30441ad
CB
143}
144
145/* TODO: Figure out tag memory details and drop the over-cautious allocation.
146 */
f6bad8ab 147int
c7750cfb 148gf100_ltc_init_tag_ram(struct nvkm_fb *fb, struct nvkm_ltc_priv *ltc)
e30441ad
CB
149{
150 u32 tag_size, tag_margin, tag_align;
151 int ret;
152
eaecf032 153 /* No VRAM, no tags for now. */
b1e4553c 154 if (!fb->ram) {
c7750cfb 155 ltc->num_tags = 0;
eaecf032
AC
156 goto mm_init;
157 }
158
e30441ad 159 /* tags for 1/4 of VRAM should be enough (8192/4 per GiB of VRAM) */
c7750cfb
BS
160 ltc->num_tags = (fb->ram->size >> 17) / 4;
161 if (ltc->num_tags > (1 << 17))
162 ltc->num_tags = 1 << 17; /* we have 17 bits in PTE */
163 ltc->num_tags = (ltc->num_tags + 63) & ~63; /* round up to 64 */
e30441ad 164
c7750cfb 165 tag_align = ltc->ltc_nr * 0x800;
e30441ad
CB
166 tag_margin = (tag_align < 0x6000) ? 0x6000 : tag_align;
167
168 /* 4 part 4 sub: 0x2000 bytes for 56 tags */
169 /* 3 part 4 sub: 0x6000 bytes for 168 tags */
170 /*
171 * About 147 bytes per tag. Let's be safe and allocate x2, which makes
172 * 0x4980 bytes for 64 tags, and round up to 0x6000 bytes for 64 tags.
173 *
174 * For 4 GiB of memory we'll have 8192 tags which makes 3 MiB, < 0.1 %.
175 */
c7750cfb 176 tag_size = (ltc->num_tags / 64) * 0x6000 + tag_margin;
e30441ad
CB
177 tag_size += tag_align;
178 tag_size = (tag_size + 0xfff) >> 12; /* round up */
179
b1e4553c 180 ret = nvkm_mm_tail(&fb->vram, 1, 1, tag_size, tag_size, 1,
c7750cfb 181 &ltc->tag_ram);
e30441ad 182 if (ret) {
c7750cfb 183 ltc->num_tags = 0;
e30441ad 184 } else {
c7750cfb 185 u64 tag_base = ((u64)ltc->tag_ram->offset << 12) + tag_margin;
e30441ad
CB
186
187 tag_base += tag_align - 1;
c7750cfb 188 do_div(tag_base, tag_align);
e30441ad 189
c7750cfb 190 ltc->tag_base = tag_base;
e30441ad 191 }
e30441ad 192
eaecf032 193mm_init:
c7750cfb 194 ret = nvkm_mm_init(&ltc->tags, 0, ltc->num_tags, 1);
e30441ad
CB
195 return ret;
196}
197
95484b57 198int
2799bba6
BS
199gf100_ltc_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
200 struct nvkm_oclass *oclass, void *data, u32 size,
201 struct nvkm_object **pobject)
861d2107 202{
b1e4553c 203 struct nvkm_fb *fb = nvkm_fb(parent);
c7750cfb 204 struct nvkm_ltc_priv *ltc;
49debbe4
BS
205 u32 parts, mask;
206 int ret, i;
861d2107 207
c7750cfb
BS
208 ret = nvkm_ltc_create(parent, engine, oclass, &ltc);
209 *pobject = nv_object(ltc);
861d2107
BS
210 if (ret)
211 return ret;
212
c7750cfb
BS
213 parts = nv_rd32(ltc, 0x022438);
214 mask = nv_rd32(ltc, 0x022554);
49debbe4
BS
215 for (i = 0; i < parts; i++) {
216 if (!(mask & (1 << i)))
c7750cfb 217 ltc->ltc_nr++;
49debbe4 218 }
c7750cfb 219 ltc->lts_nr = nv_rd32(ltc, 0x17e8dc) >> 28;
e30441ad 220
c7750cfb 221 ret = gf100_ltc_init_tag_ram(fb, ltc);
e30441ad
CB
222 if (ret)
223 return ret;
224
c7750cfb 225 nv_subdev(ltc)->intr = gf100_ltc_intr;
52f9a4d7
ML
226 return 0;
227}
228
2799bba6 229struct nvkm_oclass *
95484b57
BS
230gf100_ltc_oclass = &(struct nvkm_ltc_impl) {
231 .base.handle = NV_SUBDEV(LTC, 0xc0),
2799bba6 232 .base.ofuncs = &(struct nvkm_ofuncs) {
95484b57
BS
233 .ctor = gf100_ltc_ctor,
234 .dtor = gf100_ltc_dtor,
235 .init = gf100_ltc_init,
236 .fini = _nvkm_ltc_fini,
861d2107 237 },
95484b57
BS
238 .intr = gf100_ltc_intr,
239 .cbc_clear = gf100_ltc_cbc_clear,
240 .cbc_wait = gf100_ltc_cbc_wait,
f38fdb6a
BS
241 .zbc = 16,
242 .zbc_clear_color = gf100_ltc_zbc_clear_color,
243 .zbc_clear_depth = gf100_ltc_zbc_clear_depth,
95484b57 244}.base;