Merge branch 'nvmf-4.8-rc' of git://git.infradead.org/nvme-fabrics into for-linus
[deliverable/linux.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
e30441ad
CB
26#include <subdev/fb.h>
27#include <subdev/timer.h>
861d2107 28
95484b57 29void
70bc7182 30gf100_ltc_cbc_clear(struct nvkm_ltc *ltc, u32 start, u32 limit)
95484b57 31{
70bc7182 32 struct nvkm_device *device = ltc->subdev.device;
99336ed3
BS
33 nvkm_wr32(device, 0x17e8cc, start);
34 nvkm_wr32(device, 0x17e8d0, limit);
35 nvkm_wr32(device, 0x17e8c8, 0x00000004);
95484b57
BS
36}
37
38void
70bc7182 39gf100_ltc_cbc_wait(struct nvkm_ltc *ltc)
95484b57 40{
70bc7182 41 struct nvkm_device *device = ltc->subdev.device;
95484b57 42 int c, s;
c7750cfb 43 for (c = 0; c < ltc->ltc_nr; c++) {
1302bcbb
BS
44 for (s = 0; s < ltc->lts_nr; s++) {
45 const u32 addr = 0x1410c8 + (c * 0x2000) + (s * 0x400);
46 nvkm_msec(device, 2000,
47 if (!nvkm_rd32(device, addr))
48 break;
49 );
50 }
95484b57
BS
51 }
52}
861d2107 53
f38fdb6a 54void
70bc7182 55gf100_ltc_zbc_clear_color(struct nvkm_ltc *ltc, int i, const u32 color[4])
f38fdb6a 56{
70bc7182 57 struct nvkm_device *device = ltc->subdev.device;
99336ed3
BS
58 nvkm_mask(device, 0x17ea44, 0x0000000f, i);
59 nvkm_wr32(device, 0x17ea48, color[0]);
60 nvkm_wr32(device, 0x17ea4c, color[1]);
61 nvkm_wr32(device, 0x17ea50, color[2]);
62 nvkm_wr32(device, 0x17ea54, color[3]);
f38fdb6a
BS
63}
64
65void
70bc7182 66gf100_ltc_zbc_clear_depth(struct nvkm_ltc *ltc, int i, const u32 depth)
f38fdb6a 67{
70bc7182 68 struct nvkm_device *device = ltc->subdev.device;
99336ed3
BS
69 nvkm_mask(device, 0x17ea44, 0x0000000f, i);
70 nvkm_wr32(device, 0x17ea58, depth);
f38fdb6a
BS
71}
72
86b40432 73const struct nvkm_bitfield
a1fc50b4
BS
74gf100_ltc_lts_intr_name[] = {
75 { 0x00000001, "IDLE_ERROR_IQ" },
76 { 0x00000002, "IDLE_ERROR_CBC" },
77 { 0x00000004, "IDLE_ERROR_TSTG" },
78 { 0x00000008, "IDLE_ERROR_DSTG" },
79 { 0x00000010, "EVICTED_CB" },
80 { 0x00000020, "ILLEGAL_COMPSTAT" },
81 { 0x00000040, "BLOCKLINEAR_CB" },
82 { 0x00000100, "ECC_SEC_ERROR" },
83 { 0x00000200, "ECC_DED_ERROR" },
84 { 0x00000400, "DEBUG" },
85 { 0x00000800, "ATOMIC_TO_Z" },
86 { 0x00001000, "ILLEGAL_ATOMIC" },
87 { 0x00002000, "BLKACTIVITY_ERR" },
88 {}
89};
90
861d2107 91static void
70bc7182 92gf100_ltc_lts_intr(struct nvkm_ltc *ltc, int c, int s)
861d2107 93{
70bc7182 94 struct nvkm_subdev *subdev = &ltc->subdev;
59e1a2f1 95 struct nvkm_device *device = subdev->device;
c7750cfb 96 u32 base = 0x141000 + (c * 0x2000) + (s * 0x400);
99336ed3 97 u32 intr = nvkm_rd32(device, base + 0x020);
a1fc50b4 98 u32 stat = intr & 0x0000ffff;
59e1a2f1 99 char msg[128];
861d2107
BS
100
101 if (stat) {
59e1a2f1
BS
102 nvkm_snprintbf(msg, sizeof(msg), gf100_ltc_lts_intr_name, stat);
103 nvkm_error(subdev, "LTC%d_LTS%d: %08x [%s]\n", c, s, stat, msg);
861d2107 104 }
a1fc50b4 105
99336ed3 106 nvkm_wr32(device, base + 0x020, intr);
861d2107
BS
107}
108
95484b57 109void
70bc7182 110gf100_ltc_intr(struct nvkm_ltc *ltc)
861d2107 111{
70bc7182 112 struct nvkm_device *device = ltc->subdev.device;
f6bad8ab
BS
113 u32 mask;
114
99336ed3 115 mask = nvkm_rd32(device, 0x00017c);
f6bad8ab 116 while (mask) {
c7750cfb
BS
117 u32 s, c = __ffs(mask);
118 for (s = 0; s < ltc->lts_nr; s++)
119 gf100_ltc_lts_intr(ltc, c, s);
120 mask &= ~(1 << c);
861d2107 121 }
861d2107
BS
122}
123
a0a49bac
AC
124void
125gf100_ltc_invalidate(struct nvkm_ltc *ltc)
126{
127 struct nvkm_device *device = ltc->subdev.device;
128 s64 taken;
129
130 nvkm_wr32(device, 0x70004, 0x00000001);
ab08f38c 131 taken = nvkm_wait_msec(device, 2000, 0x70004, 0x00000003, 0x00000000);
a0a49bac
AC
132
133 if (taken > 0)
134 nvkm_debug(&ltc->subdev, "LTC invalidate took %lld ns\n", taken);
135}
136
137void
138gf100_ltc_flush(struct nvkm_ltc *ltc)
139{
140 struct nvkm_device *device = ltc->subdev.device;
141 s64 taken;
142
143 nvkm_wr32(device, 0x70010, 0x00000001);
ab08f38c 144 taken = nvkm_wait_msec(device, 2000, 0x70010, 0x00000003, 0x00000000);
a0a49bac
AC
145
146 if (taken > 0)
147 nvkm_debug(&ltc->subdev, "LTC flush took %lld ns\n", taken);
148}
149
e30441ad
CB
150/* TODO: Figure out tag memory details and drop the over-cautious allocation.
151 */
f6bad8ab 152int
70bc7182 153gf100_ltc_oneinit_tag_ram(struct nvkm_ltc *ltc)
e30441ad 154{
70bc7182 155 struct nvkm_ram *ram = ltc->subdev.device->fb->ram;
e30441ad
CB
156 u32 tag_size, tag_margin, tag_align;
157 int ret;
158
eaecf032 159 /* No VRAM, no tags for now. */
d36a99d2 160 if (!ram) {
c7750cfb 161 ltc->num_tags = 0;
eaecf032
AC
162 goto mm_init;
163 }
164
e30441ad 165 /* tags for 1/4 of VRAM should be enough (8192/4 per GiB of VRAM) */
d36a99d2 166 ltc->num_tags = (ram->size >> 17) / 4;
c7750cfb
BS
167 if (ltc->num_tags > (1 << 17))
168 ltc->num_tags = 1 << 17; /* we have 17 bits in PTE */
169 ltc->num_tags = (ltc->num_tags + 63) & ~63; /* round up to 64 */
e30441ad 170
c7750cfb 171 tag_align = ltc->ltc_nr * 0x800;
e30441ad
CB
172 tag_margin = (tag_align < 0x6000) ? 0x6000 : tag_align;
173
174 /* 4 part 4 sub: 0x2000 bytes for 56 tags */
175 /* 3 part 4 sub: 0x6000 bytes for 168 tags */
176 /*
177 * About 147 bytes per tag. Let's be safe and allocate x2, which makes
178 * 0x4980 bytes for 64 tags, and round up to 0x6000 bytes for 64 tags.
179 *
180 * For 4 GiB of memory we'll have 8192 tags which makes 3 MiB, < 0.1 %.
181 */
c7750cfb 182 tag_size = (ltc->num_tags / 64) * 0x6000 + tag_margin;
e30441ad
CB
183 tag_size += tag_align;
184 tag_size = (tag_size + 0xfff) >> 12; /* round up */
185
d36a99d2 186 ret = nvkm_mm_tail(&ram->vram, 1, 1, tag_size, tag_size, 1,
c7750cfb 187 &ltc->tag_ram);
e30441ad 188 if (ret) {
c7750cfb 189 ltc->num_tags = 0;
e30441ad 190 } else {
c7750cfb 191 u64 tag_base = ((u64)ltc->tag_ram->offset << 12) + tag_margin;
e30441ad
CB
192
193 tag_base += tag_align - 1;
c7750cfb 194 do_div(tag_base, tag_align);
e30441ad 195
c7750cfb 196 ltc->tag_base = tag_base;
e30441ad 197 }
e30441ad 198
eaecf032 199mm_init:
70bc7182 200 return nvkm_mm_init(&ltc->tags, 0, ltc->num_tags, 1);
e30441ad
CB
201}
202
95484b57 203int
70bc7182 204gf100_ltc_oneinit(struct nvkm_ltc *ltc)
861d2107 205{
70bc7182
BS
206 struct nvkm_device *device = ltc->subdev.device;
207 const u32 parts = nvkm_rd32(device, 0x022438);
208 const u32 mask = nvkm_rd32(device, 0x022554);
209 const u32 slice = nvkm_rd32(device, 0x17e8dc) >> 28;
210 int i;
861d2107 211
49debbe4
BS
212 for (i = 0; i < parts; i++) {
213 if (!(mask & (1 << i)))
c7750cfb 214 ltc->ltc_nr++;
49debbe4 215 }
70bc7182
BS
216 ltc->lts_nr = slice;
217
218 return gf100_ltc_oneinit_tag_ram(ltc);
219}
e30441ad 220
70bc7182
BS
221static void
222gf100_ltc_init(struct nvkm_ltc *ltc)
223{
224 struct nvkm_device *device = ltc->subdev.device;
225 u32 lpg128 = !(nvkm_rd32(device, 0x100c80) & 0x00000001);
e30441ad 226
70bc7182
BS
227 nvkm_mask(device, 0x17e820, 0x00100000, 0x00000000); /* INTR_EN &= ~0x10 */
228 nvkm_wr32(device, 0x17e8d8, ltc->ltc_nr);
229 nvkm_wr32(device, 0x17e8d4, ltc->tag_base);
230 nvkm_mask(device, 0x17e8c0, 0x00000002, lpg128 ? 0x00000002 : 0x00000000);
52f9a4d7
ML
231}
232
70bc7182
BS
233static const struct nvkm_ltc_func
234gf100_ltc = {
235 .oneinit = gf100_ltc_oneinit,
236 .init = gf100_ltc_init,
95484b57
BS
237 .intr = gf100_ltc_intr,
238 .cbc_clear = gf100_ltc_cbc_clear,
239 .cbc_wait = gf100_ltc_cbc_wait,
f38fdb6a
BS
240 .zbc = 16,
241 .zbc_clear_color = gf100_ltc_zbc_clear_color,
242 .zbc_clear_depth = gf100_ltc_zbc_clear_depth,
a0a49bac
AC
243 .invalidate = gf100_ltc_invalidate,
244 .flush = gf100_ltc_flush,
70bc7182
BS
245};
246
247int
248gf100_ltc_new(struct nvkm_device *device, int index, struct nvkm_ltc **pltc)
249{
250 return nvkm_ltc_new_(&gf100_ltc, device, index, pltc);
251}
This page took 0.229995 seconds and 5 git commands to generate.