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 24
/*
 * 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
 */

25 26
#include <subdev/fb.h>
#include <subdev/timer.h>
27

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include "priv.h"

void
gf100_ltc_cbc_clear(struct nvkm_ltc_priv *priv, u32 start, u32 limit)
{
	nv_wr32(priv, 0x17e8cc, start);
	nv_wr32(priv, 0x17e8d0, limit);
	nv_wr32(priv, 0x17e8c8, 0x00000004);
}

void
gf100_ltc_cbc_wait(struct nvkm_ltc_priv *priv)
{
	int c, s;
	for (c = 0; c < priv->ltc_nr; c++) {
		for (s = 0; s < priv->lts_nr; s++)
			nv_wait(priv, 0x1410c8 + c * 0x2000 + s * 0x400, ~0, 0);
	}
}
47

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

void
gf100_ltc_zbc_clear_depth(struct nvkm_ltc_priv *priv, int i, const u32 depth)
{
	nv_mask(priv, 0x17ea44, 0x0000000f, i);
	nv_wr32(priv, 0x17ea58, depth);
}

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
static const struct nouveau_bitfield
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
84
gf100_ltc_lts_intr(struct nvkm_ltc_priv *priv, int ltc, int lts)
85
{
86
	u32 base = 0x141000 + (ltc * 0x2000) + (lts * 0x400);
87 88
	u32 intr = nv_rd32(priv, base + 0x020);
	u32 stat = intr & 0x0000ffff;
89 90

	if (stat) {
91 92 93
		nv_info(priv, "LTC%d_LTS%d:", ltc, lts);
		nouveau_bitfield_print(gf100_ltc_lts_intr_name, stat);
		pr_cont("\n");
94
	}
95 96

	nv_wr32(priv, base + 0x020, intr);
97 98
}

99 100
void
gf100_ltc_intr(struct nouveau_subdev *subdev)
101
{
102
	struct nvkm_ltc_priv *priv = (void *)subdev;
103 104 105 106 107 108
	u32 mask;

	mask = nv_rd32(priv, 0x00017c);
	while (mask) {
		u32 lts, ltc = __ffs(mask);
		for (lts = 0; lts < priv->lts_nr; lts++)
109
			gf100_ltc_lts_intr(priv, ltc, lts);
110
		mask &= ~(1 << ltc);
111 112 113
	}
}

114 115
static int
gf100_ltc_init(struct nouveau_object *object)
116
{
117
	struct nvkm_ltc_priv *priv = (void *)object;
118
	u32 lpg128 = !(nv_rd32(priv, 0x100c80) & 0x00000001);
119 120
	int ret;

121
	ret = nvkm_ltc_init(priv);
122
	if (ret)
123
		return ret;
124

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

132
void
133
gf100_ltc_dtor(struct nouveau_object *object)
134
{
135 136
	struct nouveau_fb *pfb = nouveau_fb(object);
	struct nvkm_ltc_priv *priv = (void *)object;
137

138 139
	nouveau_mm_fini(&priv->tags);
	nouveau_mm_free(&pfb->vram, &priv->tag_ram);
140

141
	nvkm_ltc_destroy(priv);
142 143 144 145
}

/* TODO: Figure out tag memory details and drop the over-cautious allocation.
 */
146
int
147
gf100_ltc_init_tag_ram(struct nouveau_fb *pfb, struct nvkm_ltc_priv *priv)
148 149 150 151 152
{
	u32 tag_size, tag_margin, tag_align;
	int ret;

	/* tags for 1/4 of VRAM should be enough (8192/4 per GiB of VRAM) */
153
	priv->num_tags = (pfb->ram->size >> 17) / 4;
154 155 156 157
	if (priv->num_tags > (1 << 17))
		priv->num_tags = 1 << 17; /* we have 17 bits in PTE */
	priv->num_tags = (priv->num_tags + 63) & ~63; /* round up to 64 */

158
	tag_align = priv->ltc_nr * 0x800;
159 160 161 162 163 164 165 166 167 168 169 170 171 172
	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 %.
	 */
	tag_size  = (priv->num_tags / 64) * 0x6000 + tag_margin;
	tag_size += tag_align;
	tag_size  = (tag_size + 0xfff) >> 12; /* round up */

173
	ret = nouveau_mm_tail(&pfb->vram, 1, 1, tag_size, tag_size, 1,
174 175 176 177
	                      &priv->tag_ram);
	if (ret) {
		priv->num_tags = 0;
	} else {
178
		u64 tag_base = ((u64)priv->tag_ram->offset << 12) + tag_margin;
179 180

		tag_base += tag_align - 1;
181
		ret = do_div(tag_base, tag_align);
182

183
		priv->tag_base = tag_base;
184 185
	}

186
	ret = nouveau_mm_init(&priv->tags, 0, priv->num_tags, 1);
187 188 189
	return ret;
}

190 191
int
gf100_ltc_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
192 193 194
	       struct nouveau_oclass *oclass, void *data, u32 size,
	       struct nouveau_object **pobject)
{
195
	struct nouveau_fb *pfb = nouveau_fb(parent);
196
	struct nvkm_ltc_priv *priv;
197 198
	u32 parts, mask;
	int ret, i;
199

200
	ret = nvkm_ltc_create(parent, engine, oclass, &priv);
201 202 203 204
	*pobject = nv_object(priv);
	if (ret)
		return ret;

205 206 207 208
	parts = nv_rd32(priv, 0x022438);
	mask = nv_rd32(priv, 0x022554);
	for (i = 0; i < parts; i++) {
		if (!(mask & (1 << i)))
209
			priv->ltc_nr++;
210
	}
211
	priv->lts_nr = nv_rd32(priv, 0x17e8dc) >> 28;
212

213
	ret = gf100_ltc_init_tag_ram(pfb, priv);
214 215 216
	if (ret)
		return ret;

217
	nv_subdev(priv)->intr = gf100_ltc_intr;
218 219 220
	return 0;
}

221
struct nouveau_oclass *
222 223 224 225 226 227 228
gf100_ltc_oclass = &(struct nvkm_ltc_impl) {
	.base.handle = NV_SUBDEV(LTC, 0xc0),
	.base.ofuncs = &(struct nouveau_ofuncs) {
		.ctor = gf100_ltc_ctor,
		.dtor = gf100_ltc_dtor,
		.init = gf100_ltc_init,
		.fini = _nvkm_ltc_fini,
229
	},
230 231 232
	.intr = gf100_ltc_intr,
	.cbc_clear = gf100_ltc_cbc_clear,
	.cbc_wait = gf100_ltc_cbc_wait,
B
Ben Skeggs 已提交
233 234 235
	.zbc = 16,
	.zbc_clear_color = gf100_ltc_zbc_clear_color,
	.zbc_clear_depth = gf100_ltc_zbc_clear_depth,
236
}.base;