gf100.c 6.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2012 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors: Ben Skeggs
 */
24
#include "priv.h"
25

26
#include <core/enum.h>
27 28
#include <subdev/fb.h>
#include <subdev/timer.h>
29

30
void
B
Ben Skeggs 已提交
31
gf100_ltc_cbc_clear(struct nvkm_ltc_priv *ltc, u32 start, u32 limit)
32
{
B
Ben Skeggs 已提交
33 34 35
	nv_wr32(ltc, 0x17e8cc, start);
	nv_wr32(ltc, 0x17e8d0, limit);
	nv_wr32(ltc, 0x17e8c8, 0x00000004);
36 37 38
}

void
B
Ben Skeggs 已提交
39
gf100_ltc_cbc_wait(struct nvkm_ltc_priv *ltc)
40 41
{
	int c, s;
B
Ben Skeggs 已提交
42 43 44
	for (c = 0; c < ltc->ltc_nr; c++) {
		for (s = 0; s < ltc->lts_nr; s++)
			nv_wait(ltc, 0x1410c8 + c * 0x2000 + s * 0x400, ~0, 0);
45 46
	}
}
47

B
Ben Skeggs 已提交
48
void
B
Ben Skeggs 已提交
49
gf100_ltc_zbc_clear_color(struct nvkm_ltc_priv *ltc, int i, const u32 color[4])
B
Ben Skeggs 已提交
50
{
B
Ben Skeggs 已提交
51 52 53 54 55
	nv_mask(ltc, 0x17ea44, 0x0000000f, i);
	nv_wr32(ltc, 0x17ea48, color[0]);
	nv_wr32(ltc, 0x17ea4c, color[1]);
	nv_wr32(ltc, 0x17ea50, color[2]);
	nv_wr32(ltc, 0x17ea54, color[3]);
B
Ben Skeggs 已提交
56 57 58
}

void
B
Ben Skeggs 已提交
59
gf100_ltc_zbc_clear_depth(struct nvkm_ltc_priv *ltc, int i, const u32 depth)
B
Ben Skeggs 已提交
60
{
B
Ben Skeggs 已提交
61 62
	nv_mask(ltc, 0x17ea44, 0x0000000f, i);
	nv_wr32(ltc, 0x17ea58, depth);
B
Ben Skeggs 已提交
63 64
}

65
static const struct nvkm_bitfield
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
gf100_ltc_lts_intr_name[] = {
	{ 0x00000001, "IDLE_ERROR_IQ" },
	{ 0x00000002, "IDLE_ERROR_CBC" },
	{ 0x00000004, "IDLE_ERROR_TSTG" },
	{ 0x00000008, "IDLE_ERROR_DSTG" },
	{ 0x00000010, "EVICTED_CB" },
	{ 0x00000020, "ILLEGAL_COMPSTAT" },
	{ 0x00000040, "BLOCKLINEAR_CB" },
	{ 0x00000100, "ECC_SEC_ERROR" },
	{ 0x00000200, "ECC_DED_ERROR" },
	{ 0x00000400, "DEBUG" },
	{ 0x00000800, "ATOMIC_TO_Z" },
	{ 0x00001000, "ILLEGAL_ATOMIC" },
	{ 0x00002000, "BLKACTIVITY_ERR" },
	{}
};

83
static void
B
Ben Skeggs 已提交
84
gf100_ltc_lts_intr(struct nvkm_ltc_priv *ltc, int c, int s)
85
{
B
Ben Skeggs 已提交
86 87
	u32 base = 0x141000 + (c * 0x2000) + (s * 0x400);
	u32 intr = nv_rd32(ltc, base + 0x020);
88
	u32 stat = intr & 0x0000ffff;
89 90

	if (stat) {
B
Ben Skeggs 已提交
91
		nv_info(ltc, "LTC%d_LTS%d:", c, s);
92
		nvkm_bitfield_print(gf100_ltc_lts_intr_name, stat);
93
		pr_cont("\n");
94
	}
95

B
Ben Skeggs 已提交
96
	nv_wr32(ltc, base + 0x020, intr);
97 98
}

99
void
100
gf100_ltc_intr(struct nvkm_subdev *subdev)
101
{
B
Ben Skeggs 已提交
102
	struct nvkm_ltc_priv *ltc = (void *)subdev;
103 104
	u32 mask;

B
Ben Skeggs 已提交
105
	mask = nv_rd32(ltc, 0x00017c);
106
	while (mask) {
B
Ben Skeggs 已提交
107 108 109 110
		u32 s, c = __ffs(mask);
		for (s = 0; s < ltc->lts_nr; s++)
			gf100_ltc_lts_intr(ltc, c, s);
		mask &= ~(1 << c);
111 112 113
	}
}

114
static int
115
gf100_ltc_init(struct nvkm_object *object)
116
{
B
Ben Skeggs 已提交
117 118
	struct nvkm_ltc_priv *ltc = (void *)object;
	u32 lpg128 = !(nv_rd32(ltc, 0x100c80) & 0x00000001);
119 120
	int ret;

B
Ben Skeggs 已提交
121
	ret = nvkm_ltc_init(ltc);
122
	if (ret)
123
		return ret;
124

B
Ben Skeggs 已提交
125 126 127 128
	nv_mask(ltc, 0x17e820, 0x00100000, 0x00000000); /* INTR_EN &= ~0x10 */
	nv_wr32(ltc, 0x17e8d8, ltc->ltc_nr);
	nv_wr32(ltc, 0x17e8d4, ltc->tag_base);
	nv_mask(ltc, 0x17e8c0, 0x00000002, lpg128 ? 0x00000002 : 0x00000000);
129
	return 0;
130 131
}

132
void
133
gf100_ltc_dtor(struct nvkm_object *object)
134
{
B
Ben Skeggs 已提交
135
	struct nvkm_fb *fb = nvkm_fb(object);
B
Ben Skeggs 已提交
136
	struct nvkm_ltc_priv *ltc = (void *)object;
137

B
Ben Skeggs 已提交
138
	nvkm_mm_fini(&ltc->tags);
B
Ben Skeggs 已提交
139
	if (fb->ram)
B
Ben Skeggs 已提交
140
		nvkm_mm_free(&fb->vram, &ltc->tag_ram);
141

B
Ben Skeggs 已提交
142
	nvkm_ltc_destroy(ltc);
143 144 145 146
}

/* TODO: Figure out tag memory details and drop the over-cautious allocation.
 */
147
int
B
Ben Skeggs 已提交
148
gf100_ltc_init_tag_ram(struct nvkm_fb *fb, struct nvkm_ltc_priv *ltc)
149 150 151 152
{
	u32 tag_size, tag_margin, tag_align;
	int ret;

A
Alexandre Courbot 已提交
153
	/* No VRAM, no tags for now. */
B
Ben Skeggs 已提交
154
	if (!fb->ram) {
B
Ben Skeggs 已提交
155
		ltc->num_tags = 0;
A
Alexandre Courbot 已提交
156 157 158
		goto mm_init;
	}

159
	/* tags for 1/4 of VRAM should be enough (8192/4 per GiB of VRAM) */
B
Ben Skeggs 已提交
160 161 162 163
	ltc->num_tags = (fb->ram->size >> 17) / 4;
	if (ltc->num_tags > (1 << 17))
		ltc->num_tags = 1 << 17; /* we have 17 bits in PTE */
	ltc->num_tags = (ltc->num_tags + 63) & ~63; /* round up to 64 */
164

B
Ben Skeggs 已提交
165
	tag_align = ltc->ltc_nr * 0x800;
166 167 168 169 170 171 172 173 174 175
	tag_margin = (tag_align < 0x6000) ? 0x6000 : tag_align;

	/* 4 part 4 sub: 0x2000 bytes for 56 tags */
	/* 3 part 4 sub: 0x6000 bytes for 168 tags */
	/*
	 * About 147 bytes per tag. Let's be safe and allocate x2, which makes
	 * 0x4980 bytes for 64 tags, and round up to 0x6000 bytes for 64 tags.
	 *
	 * For 4 GiB of memory we'll have 8192 tags which makes 3 MiB, < 0.1 %.
	 */
B
Ben Skeggs 已提交
176
	tag_size  = (ltc->num_tags / 64) * 0x6000 + tag_margin;
177 178 179
	tag_size += tag_align;
	tag_size  = (tag_size + 0xfff) >> 12; /* round up */

B
Ben Skeggs 已提交
180
	ret = nvkm_mm_tail(&fb->vram, 1, 1, tag_size, tag_size, 1,
B
Ben Skeggs 已提交
181
			   &ltc->tag_ram);
182
	if (ret) {
B
Ben Skeggs 已提交
183
		ltc->num_tags = 0;
184
	} else {
B
Ben Skeggs 已提交
185
		u64 tag_base = ((u64)ltc->tag_ram->offset << 12) + tag_margin;
186 187

		tag_base += tag_align - 1;
B
Ben Skeggs 已提交
188
		do_div(tag_base, tag_align);
189

B
Ben Skeggs 已提交
190
		ltc->tag_base = tag_base;
191 192
	}

A
Alexandre Courbot 已提交
193
mm_init:
B
Ben Skeggs 已提交
194
	ret = nvkm_mm_init(&ltc->tags, 0, ltc->num_tags, 1);
195 196 197
	return ret;
}

198
int
199 200 201
gf100_ltc_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	       struct nvkm_oclass *oclass, void *data, u32 size,
	       struct nvkm_object **pobject)
202
{
B
Ben Skeggs 已提交
203
	struct nvkm_fb *fb = nvkm_fb(parent);
B
Ben Skeggs 已提交
204
	struct nvkm_ltc_priv *ltc;
205 206
	u32 parts, mask;
	int ret, i;
207

B
Ben Skeggs 已提交
208 209
	ret = nvkm_ltc_create(parent, engine, oclass, &ltc);
	*pobject = nv_object(ltc);
210 211 212
	if (ret)
		return ret;

B
Ben Skeggs 已提交
213 214
	parts = nv_rd32(ltc, 0x022438);
	mask = nv_rd32(ltc, 0x022554);
215 216
	for (i = 0; i < parts; i++) {
		if (!(mask & (1 << i)))
B
Ben Skeggs 已提交
217
			ltc->ltc_nr++;
218
	}
B
Ben Skeggs 已提交
219
	ltc->lts_nr = nv_rd32(ltc, 0x17e8dc) >> 28;
220

B
Ben Skeggs 已提交
221
	ret = gf100_ltc_init_tag_ram(fb, ltc);
222 223 224
	if (ret)
		return ret;

B
Ben Skeggs 已提交
225
	nv_subdev(ltc)->intr = gf100_ltc_intr;
226 227 228
	return 0;
}

229
struct nvkm_oclass *
230 231
gf100_ltc_oclass = &(struct nvkm_ltc_impl) {
	.base.handle = NV_SUBDEV(LTC, 0xc0),
232
	.base.ofuncs = &(struct nvkm_ofuncs) {
233 234 235 236
		.ctor = gf100_ltc_ctor,
		.dtor = gf100_ltc_dtor,
		.init = gf100_ltc_init,
		.fini = _nvkm_ltc_fini,
237
	},
238 239 240
	.intr = gf100_ltc_intr,
	.cbc_clear = gf100_ltc_cbc_clear,
	.cbc_wait = gf100_ltc_cbc_wait,
B
Ben Skeggs 已提交
241 242 243
	.zbc = 16,
	.zbc_clear_color = gf100_ltc_zbc_clear_color,
	.zbc_clear_depth = gf100_ltc_zbc_clear_depth,
244
}.base;