nv20.c 12.2 KB
Newer Older
1 2 3
#include "nv20.h"
#include "regs.h"

4
#include <core/client.h>
5
#include <engine/fifo.h>
6 7
#include <subdev/fb.h>
#include <subdev/timer.h>
8 9 10 11 12

/*******************************************************************************
 * Graphics object classes
 ******************************************************************************/

13
static struct nvkm_oclass
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
nv20_gr_sclass[] = {
	{ 0x0012, &nv04_gr_ofuncs, NULL }, /* beta1 */
	{ 0x0019, &nv04_gr_ofuncs, NULL }, /* clip */
	{ 0x0030, &nv04_gr_ofuncs, NULL }, /* null */
	{ 0x0039, &nv04_gr_ofuncs, NULL }, /* m2mf */
	{ 0x0043, &nv04_gr_ofuncs, NULL }, /* rop */
	{ 0x0044, &nv04_gr_ofuncs, NULL }, /* patt */
	{ 0x004a, &nv04_gr_ofuncs, NULL }, /* gdi */
	{ 0x0062, &nv04_gr_ofuncs, NULL }, /* surf2d */
	{ 0x0072, &nv04_gr_ofuncs, NULL }, /* beta4 */
	{ 0x0089, &nv04_gr_ofuncs, NULL }, /* sifm */
	{ 0x008a, &nv04_gr_ofuncs, NULL }, /* ifc */
	{ 0x0096, &nv04_gr_ofuncs, NULL }, /* celcius */
	{ 0x0097, &nv04_gr_ofuncs, NULL }, /* kelvin */
	{ 0x009e, &nv04_gr_ofuncs, NULL }, /* swzsurf */
	{ 0x009f, &nv04_gr_ofuncs, NULL }, /* imageblit */
30
	{},
31 32
};

33 34 35
/*******************************************************************************
 * PGRAPH context
 ******************************************************************************/
36

37
static int
38 39 40
nv20_gr_context_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
		     struct nvkm_oclass *oclass, void *data, u32 size,
		     struct nvkm_object **pobject)
41
{
42
	struct nv20_gr_chan *chan;
43
	struct nvkm_gpuobj *image;
44
	int ret, i;
45

46 47
	ret = nvkm_gr_context_create(parent, engine, oclass, NULL, 0x37f0,
				     16, NVOBJ_FLAG_ZERO_ALLOC, &chan);
48 49 50
	*pobject = nv_object(chan);
	if (ret)
		return ret;
51

52
	chan->chid = nvkm_fifo_chan(parent)->chid;
53 54 55 56 57 58 59 60 61 62
	image = &chan->base.base.gpuobj;

	nvkm_kmap(image);
	nvkm_wo32(image, 0x0000, 0x00000001 | (chan->chid << 24));
	nvkm_wo32(image, 0x033c, 0xffff0000);
	nvkm_wo32(image, 0x03a0, 0x0fff0000);
	nvkm_wo32(image, 0x03a4, 0x0fff0000);
	nvkm_wo32(image, 0x047c, 0x00000101);
	nvkm_wo32(image, 0x0490, 0x00000111);
	nvkm_wo32(image, 0x04a8, 0x44400000);
63
	for (i = 0x04d4; i <= 0x04e0; i += 4)
64
		nvkm_wo32(image, i, 0x00030303);
65
	for (i = 0x04f4; i <= 0x0500; i += 4)
66
		nvkm_wo32(image, i, 0x00080000);
67
	for (i = 0x050c; i <= 0x0518; i += 4)
68
		nvkm_wo32(image, i, 0x01012000);
69
	for (i = 0x051c; i <= 0x0528; i += 4)
70
		nvkm_wo32(image, i, 0x000105b8);
71
	for (i = 0x052c; i <= 0x0538; i += 4)
72
		nvkm_wo32(image, i, 0x00080008);
73
	for (i = 0x055c; i <= 0x0598; i += 4)
74 75 76 77 78 79 80
		nvkm_wo32(image, i, 0x07ff0000);
	nvkm_wo32(image, 0x05a4, 0x4b7fffff);
	nvkm_wo32(image, 0x05fc, 0x00000001);
	nvkm_wo32(image, 0x0604, 0x00004000);
	nvkm_wo32(image, 0x0610, 0x00000001);
	nvkm_wo32(image, 0x0618, 0x00040000);
	nvkm_wo32(image, 0x061c, 0x00010000);
81
	for (i = 0x1c1c; i <= 0x248c; i += 16) {
82 83 84
		nvkm_wo32(image, (i + 0), 0x10700ff9);
		nvkm_wo32(image, (i + 4), 0x0436086c);
		nvkm_wo32(image, (i + 8), 0x000c001b);
85
	}
86 87 88 89 90 91 92 93 94 95 96 97
	nvkm_wo32(image, 0x281c, 0x3f800000);
	nvkm_wo32(image, 0x2830, 0x3f800000);
	nvkm_wo32(image, 0x285c, 0x40000000);
	nvkm_wo32(image, 0x2860, 0x3f800000);
	nvkm_wo32(image, 0x2864, 0x3f000000);
	nvkm_wo32(image, 0x286c, 0x40000000);
	nvkm_wo32(image, 0x2870, 0x3f800000);
	nvkm_wo32(image, 0x2878, 0xbf800000);
	nvkm_wo32(image, 0x2880, 0xbf800000);
	nvkm_wo32(image, 0x34a4, 0x000fe000);
	nvkm_wo32(image, 0x3530, 0x000003f8);
	nvkm_wo32(image, 0x3540, 0x002fe000);
98
	for (i = 0x355c; i <= 0x3578; i += 4)
99 100
		nvkm_wo32(image, i, 0x001c527c);
	nvkm_done(image);
101
	return 0;
102 103
}

104
int
105
nv20_gr_context_init(struct nvkm_object *object)
106
{
B
Ben Skeggs 已提交
107
	struct nv20_gr *gr = (void *)object->engine;
108
	struct nv20_gr_chan *chan = (void *)object;
109
	int ret;
110

111
	ret = nvkm_gr_context_init(&chan->base);
112 113
	if (ret)
		return ret;
114

115 116 117
	nvkm_kmap(gr->ctxtab);
	nvkm_wo32(gr->ctxtab, chan->chid * 4, nv_gpuobj(chan)->addr >> 4);
	nvkm_done(gr->ctxtab);
118
	return 0;
119 120
}

121
int
122
nv20_gr_context_fini(struct nvkm_object *object, bool suspend)
123
{
B
Ben Skeggs 已提交
124
	struct nv20_gr *gr = (void *)object->engine;
125
	struct nv20_gr_chan *chan = (void *)object;
126
	struct nvkm_device *device = gr->base.engine.subdev.device;
127 128
	int chid = -1;

129 130 131
	nvkm_mask(device, 0x400720, 0x00000001, 0x00000000);
	if (nvkm_rd32(device, 0x400144) & 0x00010000)
		chid = (nvkm_rd32(device, 0x400148) & 0x1f000000) >> 24;
132
	if (chan->chid == chid) {
133 134
		nvkm_wr32(device, 0x400784, nv_gpuobj(chan)->addr >> 4);
		nvkm_wr32(device, 0x400788, 0x00000002);
135 136 137 138
		nvkm_msec(device, 2000,
			if (!nvkm_rd32(device, 0x400700))
				break;
		);
139 140
		nvkm_wr32(device, 0x400144, 0x10000000);
		nvkm_mask(device, 0x400148, 0xff000000, 0x1f000000);
141
	}
142
	nvkm_mask(device, 0x400720, 0x00000001, 0x00000001);
143

144 145 146
	nvkm_kmap(gr->ctxtab);
	nvkm_wo32(gr->ctxtab, chan->chid * 4, 0x00000000);
	nvkm_done(gr->ctxtab);
147

148
	return nvkm_gr_context_fini(&chan->base, suspend);
149 150
}

151
static struct nvkm_oclass
152
nv20_gr_cclass = {
153
	.handle = NV_ENGCTX(GR, 0x20),
154
	.ofuncs = &(struct nvkm_ofuncs) {
155
		.ctor = nv20_gr_context_ctor,
156
		.dtor = _nvkm_gr_context_dtor,
157 158
		.init = nv20_gr_context_init,
		.fini = nv20_gr_context_fini,
159 160
		.rd32 = _nvkm_gr_context_rd32,
		.wr32 = _nvkm_gr_context_wr32,
161 162
	},
};
163

164 165 166
/*******************************************************************************
 * PGRAPH engine/subdev functions
 ******************************************************************************/
167 168

void
169
nv20_gr_tile_prog(struct nvkm_engine *engine, int i)
170
{
B
Ben Skeggs 已提交
171
	struct nv20_gr *gr = (void *)engine;
172 173 174
	struct nvkm_device *device = gr->base.engine.subdev.device;
	struct nvkm_fifo *fifo = device->fifo;
	struct nvkm_fb_tile *tile = &device->fb->tile.region[i];
175
	unsigned long flags;
176

B
Ben Skeggs 已提交
177
	fifo->pause(fifo, &flags);
B
Ben Skeggs 已提交
178
	nv04_gr_idle(gr);
179

180 181 182
	nvkm_wr32(device, NV20_PGRAPH_TLIMIT(i), tile->limit);
	nvkm_wr32(device, NV20_PGRAPH_TSIZE(i), tile->pitch);
	nvkm_wr32(device, NV20_PGRAPH_TILE(i), tile->addr);
183

184 185 186 187 188 189
	nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0030 + 4 * i);
	nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->limit);
	nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0050 + 4 * i);
	nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->pitch);
	nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0010 + 4 * i);
	nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->addr);
190

191
	if (nv_device(engine)->chipset != 0x34) {
192 193 194
		nvkm_wr32(device, NV20_PGRAPH_ZCOMP(i), tile->zcomp);
		nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00ea0090 + 4 * i);
		nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, tile->zcomp);
195
	}
196

B
Ben Skeggs 已提交
197
	fifo->start(fifo, &flags);
198 199
}

200
void
201
nv20_gr_intr(struct nvkm_subdev *subdev)
202
{
B
Ben Skeggs 已提交
203
	struct nv20_gr *gr = (void *)subdev;
204
	struct nvkm_device *device = gr->base.engine.subdev.device;
205
	struct nvkm_fifo_chan *chan;
206 207 208 209
	u32 stat = nvkm_rd32(device, NV03_PGRAPH_INTR);
	u32 nsource = nvkm_rd32(device, NV03_PGRAPH_NSOURCE);
	u32 nstatus = nvkm_rd32(device, NV03_PGRAPH_NSTATUS);
	u32 addr = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_ADDR);
210 211 212
	u32 chid = (addr & 0x01f00000) >> 20;
	u32 subc = (addr & 0x00070000) >> 16;
	u32 mthd = (addr & 0x00001ffc);
213 214
	u32 data = nvkm_rd32(device, NV04_PGRAPH_TRAPPED_DATA);
	u32 class = nvkm_rd32(device, 0x400160 + subc * 4) & 0xfff;
215
	u32 show = stat;
216
	char msg[128], src[128], sta[128];
217
	unsigned long flags;
218

219
	chan = nvkm_fifo_chan_chid(device->fifo, chid, &flags);
220

221 222
	nvkm_wr32(device, NV03_PGRAPH_INTR, stat);
	nvkm_wr32(device, NV04_PGRAPH_FIFO, 0x00000001);
223 224

	if (show) {
225 226 227 228 229 230 231
		nvkm_snprintbf(msg, sizeof(msg), nv10_gr_intr_name, show);
		nvkm_snprintbf(src, sizeof(src), nv04_gr_nsource, nsource);
		nvkm_snprintbf(sta, sizeof(sta), nv10_gr_nstatus, nstatus);
		nvkm_error(subdev, "intr %08x [%s] nsource %08x [%s] "
				   "nstatus %08x [%s] ch %d [%s] subc %d "
				   "class %04x mthd %04x data %08x\n",
			   show, msg, nsource, src, nstatus, sta, chid,
232
			   nvkm_client_name(chan), subc, class, mthd, data);
233
	}
234

235
	nvkm_fifo_chan_put(device->fifo, flags, &chan);
236
}
237

238
static int
239 240 241
nv20_gr_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
	     struct nvkm_oclass *oclass, void *data, u32 size,
	     struct nvkm_object **pobject)
242
{
243
	struct nvkm_device *device = (void *)parent;
B
Ben Skeggs 已提交
244
	struct nv20_gr *gr;
245
	int ret;
246

B
Ben Skeggs 已提交
247 248
	ret = nvkm_gr_create(parent, engine, oclass, true, &gr);
	*pobject = nv_object(gr);
249 250
	if (ret)
		return ret;
251

252 253
	ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, 32 * 4, 16, true,
			      &gr->ctxtab);
254 255
	if (ret)
		return ret;
256

B
Ben Skeggs 已提交
257 258 259 260 261
	nv_subdev(gr)->unit = 0x00001000;
	nv_subdev(gr)->intr = nv20_gr_intr;
	nv_engine(gr)->cclass = &nv20_gr_cclass;
	nv_engine(gr)->sclass = nv20_gr_sclass;
	nv_engine(gr)->tile_prog = nv20_gr_tile_prog;
262 263 264
	return 0;
}

265
void
266
nv20_gr_dtor(struct nvkm_object *object)
267
{
B
Ben Skeggs 已提交
268
	struct nv20_gr *gr = (void *)object;
269
	nvkm_memory_del(&gr->ctxtab);
B
Ben Skeggs 已提交
270
	nvkm_gr_destroy(&gr->base);
271
}
272

273
int
274
nv20_gr_init(struct nvkm_object *object)
275
{
276
	struct nvkm_engine *engine = nv_engine(object);
B
Ben Skeggs 已提交
277
	struct nv20_gr *gr = (void *)engine;
278 279
	struct nvkm_device *device = gr->base.engine.subdev.device;
	struct nvkm_fb *fb = device->fb;
280 281
	u32 tmp, vramsz;
	int ret, i;
282

B
Ben Skeggs 已提交
283
	ret = nvkm_gr_init(&gr->base);
284 285
	if (ret)
		return ret;
286

287 288
	nvkm_wr32(device, NV20_PGRAPH_CHANNEL_CTX_TABLE,
			  nvkm_memory_addr(gr->ctxtab) >> 4);
289

B
Ben Skeggs 已提交
290
	if (nv_device(gr)->chipset == 0x20) {
291
		nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x003d0000);
292
		for (i = 0; i < 15; i++)
293
			nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, 0x00000000);
294 295 296 297
		nvkm_msec(device, 2000,
			if (!nvkm_rd32(device, 0x400700))
				break;
		);
298
	} else {
299
		nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x02c80000);
300
		for (i = 0; i < 32; i++)
301
			nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, 0x00000000);
302 303 304 305
		nvkm_msec(device, 2000,
			if (!nvkm_rd32(device, 0x400700))
				break;
		);
306 307
	}

308 309
	nvkm_wr32(device, NV03_PGRAPH_INTR   , 0xFFFFFFFF);
	nvkm_wr32(device, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
310

311 312 313 314 315 316
	nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
	nvkm_wr32(device, NV04_PGRAPH_DEBUG_0, 0x00000000);
	nvkm_wr32(device, NV04_PGRAPH_DEBUG_1, 0x00118700);
	nvkm_wr32(device, NV04_PGRAPH_DEBUG_3, 0xF3CE0475); /* 0x4 = auto ctx switch */
	nvkm_wr32(device, NV10_PGRAPH_DEBUG_4, 0x00000000);
	nvkm_wr32(device, 0x40009C           , 0x00000040);
317

B
Ben Skeggs 已提交
318
	if (nv_device(gr)->chipset >= 0x25) {
319 320 321 322 323 324
		nvkm_wr32(device, 0x400890, 0x00a8cfff);
		nvkm_wr32(device, 0x400610, 0x304B1FB6);
		nvkm_wr32(device, 0x400B80, 0x1cbd3883);
		nvkm_wr32(device, 0x400B84, 0x44000000);
		nvkm_wr32(device, 0x400098, 0x40000080);
		nvkm_wr32(device, 0x400B88, 0x000000ff);
325

326
	} else {
327 328 329 330 331 332 333 334 335
		nvkm_wr32(device, 0x400880, 0x0008c7df);
		nvkm_wr32(device, 0x400094, 0x00000005);
		nvkm_wr32(device, 0x400B80, 0x45eae20e);
		nvkm_wr32(device, 0x400B84, 0x24000000);
		nvkm_wr32(device, 0x400098, 0x00000040);
		nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00E00038);
		nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , 0x00000030);
		nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00E10038);
		nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , 0x00000030);
336
	}
337

338
	/* Turn all the tiling regions off. */
B
Ben Skeggs 已提交
339
	for (i = 0; i < fb->tile.regions; i++)
340
		engine->tile_prog(engine, i);
341

342 343 344
	nvkm_wr32(device, 0x4009a0, nvkm_rd32(device, 0x100324));
	nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA000C);
	nvkm_wr32(device, NV10_PGRAPH_RDI_DATA, nvkm_rd32(device, 0x100324));
345

346 347
	nvkm_wr32(device, NV10_PGRAPH_CTX_CONTROL, 0x10000100);
	nvkm_wr32(device, NV10_PGRAPH_STATE      , 0xFFFFFFFF);
348

349 350 351 352
	tmp = nvkm_rd32(device, NV10_PGRAPH_SURFACE) & 0x0007ff00;
	nvkm_wr32(device, NV10_PGRAPH_SURFACE, tmp);
	tmp = nvkm_rd32(device, NV10_PGRAPH_SURFACE) | 0x00020100;
	nvkm_wr32(device, NV10_PGRAPH_SURFACE, tmp);
353

354
	/* begin RAM config */
B
Ben Skeggs 已提交
355
	vramsz = nv_device_resource_len(nv_device(gr), 1) - 1;
356 357 358 359 360 361 362 363 364 365
	nvkm_wr32(device, 0x4009A4, nvkm_rd32(device, 0x100200));
	nvkm_wr32(device, 0x4009A8, nvkm_rd32(device, 0x100204));
	nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0000);
	nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , nvkm_rd32(device, 0x100200));
	nvkm_wr32(device, NV10_PGRAPH_RDI_INDEX, 0x00EA0004);
	nvkm_wr32(device, NV10_PGRAPH_RDI_DATA , nvkm_rd32(device, 0x100204));
	nvkm_wr32(device, 0x400820, 0);
	nvkm_wr32(device, 0x400824, 0);
	nvkm_wr32(device, 0x400864, vramsz - 1);
	nvkm_wr32(device, 0x400868, vramsz - 1);
366

367
	/* interesting.. the below overwrites some of the tile setup above.. */
368 369
	nvkm_wr32(device, 0x400B20, 0x00000000);
	nvkm_wr32(device, 0x400B04, 0xFFFFFFFF);
370

371 372 373 374
	nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_XMIN, 0);
	nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_YMIN, 0);
	nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_XMAX, 0x7fff);
	nvkm_wr32(device, NV03_PGRAPH_ABS_UCLIP_YMAX, 0x7fff);
375 376
	return 0;
}
377

378
struct nvkm_oclass
379
nv20_gr_oclass = {
380
	.handle = NV_ENGINE(GR, 0x20),
381
	.ofuncs = &(struct nvkm_ofuncs) {
382 383 384
		.ctor = nv20_gr_ctor,
		.dtor = nv20_gr_dtor,
		.init = nv20_gr_init,
385
		.fini = _nvkm_gr_fini,
386 387
	},
};