gf100.c 7.1 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
{
33 34 35 36
	struct nvkm_device *device = ltc->base.subdev.device;
	nvkm_wr32(device, 0x17e8cc, start);
	nvkm_wr32(device, 0x17e8d0, limit);
	nvkm_wr32(device, 0x17e8c8, 0x00000004);
37 38 39
}

void
B
Ben Skeggs 已提交
40
gf100_ltc_cbc_wait(struct nvkm_ltc_priv *ltc)
41
{
42
	struct nvkm_device *device = ltc->base.subdev.device;
43
	int c, s;
B
Ben Skeggs 已提交
44
	for (c = 0; c < ltc->ltc_nr; c++) {
45 46 47 48 49 50 51
		for (s = 0; s < ltc->lts_nr; s++) {
			const u32 addr = 0x1410c8 + (c * 0x2000) + (s * 0x400);
			nvkm_msec(device, 2000,
				if (!nvkm_rd32(device, addr))
					break;
			);
		}
52 53
	}
}
54

B
Ben Skeggs 已提交
55
void
B
Ben Skeggs 已提交
56
gf100_ltc_zbc_clear_color(struct nvkm_ltc_priv *ltc, int i, const u32 color[4])
B
Ben Skeggs 已提交
57
{
58 59 60 61 62 63
	struct nvkm_device *device = ltc->base.subdev.device;
	nvkm_mask(device, 0x17ea44, 0x0000000f, i);
	nvkm_wr32(device, 0x17ea48, color[0]);
	nvkm_wr32(device, 0x17ea4c, color[1]);
	nvkm_wr32(device, 0x17ea50, color[2]);
	nvkm_wr32(device, 0x17ea54, color[3]);
B
Ben Skeggs 已提交
64 65 66
}

void
B
Ben Skeggs 已提交
67
gf100_ltc_zbc_clear_depth(struct nvkm_ltc_priv *ltc, int i, const u32 depth)
B
Ben Skeggs 已提交
68
{
69 70 71
	struct nvkm_device *device = ltc->base.subdev.device;
	nvkm_mask(device, 0x17ea44, 0x0000000f, i);
	nvkm_wr32(device, 0x17ea58, depth);
B
Ben Skeggs 已提交
72 73
}

74
static const struct nvkm_bitfield
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
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" },
	{}
};

92
static void
B
Ben Skeggs 已提交
93
gf100_ltc_lts_intr(struct nvkm_ltc_priv *ltc, int c, int s)
94
{
95 96
	struct nvkm_subdev *subdev = &ltc->base.subdev;
	struct nvkm_device *device = subdev->device;
B
Ben Skeggs 已提交
97
	u32 base = 0x141000 + (c * 0x2000) + (s * 0x400);
98
	u32 intr = nvkm_rd32(device, base + 0x020);
99
	u32 stat = intr & 0x0000ffff;
100
	char msg[128];
101 102

	if (stat) {
103 104
		nvkm_snprintbf(msg, sizeof(msg), gf100_ltc_lts_intr_name, stat);
		nvkm_error(subdev, "LTC%d_LTS%d: %08x [%s]\n", c, s, stat, msg);
105
	}
106

107
	nvkm_wr32(device, base + 0x020, intr);
108 109
}

110
void
111
gf100_ltc_intr(struct nvkm_subdev *subdev)
112
{
B
Ben Skeggs 已提交
113
	struct nvkm_ltc_priv *ltc = (void *)subdev;
114
	struct nvkm_device *device = ltc->base.subdev.device;
115 116
	u32 mask;

117
	mask = nvkm_rd32(device, 0x00017c);
118
	while (mask) {
B
Ben Skeggs 已提交
119 120 121 122
		u32 s, c = __ffs(mask);
		for (s = 0; s < ltc->lts_nr; s++)
			gf100_ltc_lts_intr(ltc, c, s);
		mask &= ~(1 << c);
123 124 125
	}
}

126
static int
127
gf100_ltc_init(struct nvkm_object *object)
128
{
B
Ben Skeggs 已提交
129
	struct nvkm_ltc_priv *ltc = (void *)object;
130 131
	struct nvkm_device *device = ltc->base.subdev.device;
	u32 lpg128 = !(nvkm_rd32(device, 0x100c80) & 0x00000001);
132 133
	int ret;

B
Ben Skeggs 已提交
134
	ret = nvkm_ltc_init(ltc);
135
	if (ret)
136
		return ret;
137

138 139 140 141
	nvkm_mask(device, 0x17e820, 0x00100000, 0x00000000); /* INTR_EN &= ~0x10 */
	nvkm_wr32(device, 0x17e8d8, ltc->ltc_nr);
	nvkm_wr32(device, 0x17e8d4, ltc->tag_base);
	nvkm_mask(device, 0x17e8c0, 0x00000002, lpg128 ? 0x00000002 : 0x00000000);
142
	return 0;
143 144
}

145
void
146
gf100_ltc_dtor(struct nvkm_object *object)
147
{
B
Ben Skeggs 已提交
148
	struct nvkm_ltc_priv *ltc = (void *)object;
149
	struct nvkm_ram *ram = ltc->base.subdev.device->fb->ram;
150

B
Ben Skeggs 已提交
151
	nvkm_mm_fini(&ltc->tags);
152 153
	if (ram)
		nvkm_mm_free(&ram->vram, &ltc->tag_ram);
154

B
Ben Skeggs 已提交
155
	nvkm_ltc_destroy(ltc);
156 157 158 159
}

/* TODO: Figure out tag memory details and drop the over-cautious allocation.
 */
160
int
161
gf100_ltc_init_tag_ram(struct nvkm_ltc_priv *ltc)
162
{
163
	struct nvkm_ram *ram = ltc->base.subdev.device->fb->ram;
164 165 166
	u32 tag_size, tag_margin, tag_align;
	int ret;

A
Alexandre Courbot 已提交
167
	/* No VRAM, no tags for now. */
168
	if (!ram) {
B
Ben Skeggs 已提交
169
		ltc->num_tags = 0;
A
Alexandre Courbot 已提交
170 171 172
		goto mm_init;
	}

173
	/* tags for 1/4 of VRAM should be enough (8192/4 per GiB of VRAM) */
174
	ltc->num_tags = (ram->size >> 17) / 4;
B
Ben Skeggs 已提交
175 176 177
	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 */
178

B
Ben Skeggs 已提交
179
	tag_align = ltc->ltc_nr * 0x800;
180 181 182 183 184 185 186 187 188 189
	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 已提交
190
	tag_size  = (ltc->num_tags / 64) * 0x6000 + tag_margin;
191 192 193
	tag_size += tag_align;
	tag_size  = (tag_size + 0xfff) >> 12; /* round up */

194
	ret = nvkm_mm_tail(&ram->vram, 1, 1, tag_size, tag_size, 1,
B
Ben Skeggs 已提交
195
			   &ltc->tag_ram);
196
	if (ret) {
B
Ben Skeggs 已提交
197
		ltc->num_tags = 0;
198
	} else {
B
Ben Skeggs 已提交
199
		u64 tag_base = ((u64)ltc->tag_ram->offset << 12) + tag_margin;
200 201

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

B
Ben Skeggs 已提交
204
		ltc->tag_base = tag_base;
205 206
	}

A
Alexandre Courbot 已提交
207
mm_init:
B
Ben Skeggs 已提交
208
	ret = nvkm_mm_init(&ltc->tags, 0, ltc->num_tags, 1);
209 210 211
	return ret;
}

212
int
213 214 215
gf100_ltc_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	       struct nvkm_oclass *oclass, void *data, u32 size,
	       struct nvkm_object **pobject)
216
{
217
	struct nvkm_device *device = (void *)parent;
B
Ben Skeggs 已提交
218
	struct nvkm_ltc_priv *ltc;
219 220
	u32 parts, mask;
	int ret, i;
221

B
Ben Skeggs 已提交
222 223
	ret = nvkm_ltc_create(parent, engine, oclass, &ltc);
	*pobject = nv_object(ltc);
224 225 226
	if (ret)
		return ret;

227 228
	parts = nvkm_rd32(device, 0x022438);
	mask = nvkm_rd32(device, 0x022554);
229 230
	for (i = 0; i < parts; i++) {
		if (!(mask & (1 << i)))
B
Ben Skeggs 已提交
231
			ltc->ltc_nr++;
232
	}
233
	ltc->lts_nr = nvkm_rd32(device, 0x17e8dc) >> 28;
234

235
	ret = gf100_ltc_init_tag_ram(ltc);
236 237 238
	if (ret)
		return ret;

B
Ben Skeggs 已提交
239
	nv_subdev(ltc)->intr = gf100_ltc_intr;
240 241 242
	return 0;
}

243
struct nvkm_oclass *
244 245
gf100_ltc_oclass = &(struct nvkm_ltc_impl) {
	.base.handle = NV_SUBDEV(LTC, 0xc0),
246
	.base.ofuncs = &(struct nvkm_ofuncs) {
247 248 249 250
		.ctor = gf100_ltc_ctor,
		.dtor = gf100_ltc_dtor,
		.init = gf100_ltc_init,
		.fini = _nvkm_ltc_fini,
251
	},
252 253 254
	.intr = gf100_ltc_intr,
	.cbc_clear = gf100_ltc_cbc_clear,
	.cbc_wait = gf100_ltc_cbc_wait,
B
Ben Skeggs 已提交
255 256 257
	.zbc = 16,
	.zbc_clear_color = gf100_ltc_zbc_clear_color,
	.zbc_clear_depth = gf100_ltc_zbc_clear_depth,
258
}.base;