nv50.c 19.9 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 "nv50.h"
25
#include "head.h"
26
#include "ior.h"
27
#include "channv50.h"
28
#include "rootnv50.h"
29

30
#include <core/client.h>
31
#include <core/enum.h>
32
#include <core/ramht.h>
33 34 35 36
#include <subdev/bios.h>
#include <subdev/bios/disp.h>
#include <subdev/bios/init.h>
#include <subdev/bios/pll.h>
37
#include <subdev/devinit.h>
38
#include <subdev/timer.h>
39

40 41 42 43 44 45 46 47 48 49 50 51 52
static const struct nvkm_disp_oclass *
nv50_disp_root_(struct nvkm_disp *base)
{
	return nv50_disp(base)->func->root;
}

static void
nv50_disp_intr_(struct nvkm_disp *base)
{
	struct nv50_disp *disp = nv50_disp(base);
	disp->func->intr(disp);
}

53 54 55 56 57 58 59 60 61 62 63 64 65 66
static void
nv50_disp_fini_(struct nvkm_disp *base)
{
	struct nv50_disp *disp = nv50_disp(base);
	disp->func->fini(disp);
}

static int
nv50_disp_init_(struct nvkm_disp *base)
{
	struct nv50_disp *disp = nv50_disp(base);
	return disp->func->init(disp);
}

67 68 69 70
static void *
nv50_disp_dtor_(struct nvkm_disp *base)
{
	struct nv50_disp *disp = nv50_disp(base);
71 72 73 74

	nvkm_ramht_del(&disp->ramht);
	nvkm_gpuobj_del(&disp->inst);

75
	nvkm_event_fini(&disp->uevent);
76 77
	if (disp->wq)
		destroy_workqueue(disp->wq);
78

79
	return disp;
80 81
}

82 83 84 85 86
static int
nv50_disp_oneinit_(struct nvkm_disp *base)
{
	struct nv50_disp *disp = nv50_disp(base);
	const struct nv50_disp_func *func = disp->func;
87
	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
88
	struct nvkm_device *device = subdev->device;
89 90
	int ret, i;

91 92 93 94 95 96
	if (func->wndw.cnt) {
		disp->wndw.nr = func->wndw.cnt(&disp->base, &disp->wndw.mask);
		nvkm_debug(subdev, "Window(s): %d (%08lx)\n",
			   disp->wndw.nr, disp->wndw.mask);
	}

97 98 99 100
	disp->head.nr = func->head.cnt(&disp->base, &disp->head.mask);
	nvkm_debug(subdev, "  Head(s): %d (%02lx)\n",
		   disp->head.nr, disp->head.mask);
	for_each_set_bit(i, &disp->head.mask, disp->head.nr) {
101 102 103 104 105
		ret = func->head.new(&disp->base, i);
		if (ret)
			return ret;
	}

106 107 108 109 110 111 112 113 114
	if (func->dac.cnt) {
		disp->dac.nr = func->dac.cnt(&disp->base, &disp->dac.mask);
		nvkm_debug(subdev, "   DAC(s): %d (%02lx)\n",
			   disp->dac.nr, disp->dac.mask);
		for_each_set_bit(i, &disp->dac.mask, disp->dac.nr) {
			ret = func->dac.new(&disp->base, i);
			if (ret)
				return ret;
		}
115 116
	}

117 118 119 120 121 122 123 124 125
	if (func->pior.cnt) {
		disp->pior.nr = func->pior.cnt(&disp->base, &disp->pior.mask);
		nvkm_debug(subdev, "  PIOR(s): %d (%02lx)\n",
			   disp->pior.nr, disp->pior.mask);
		for_each_set_bit(i, &disp->pior.mask, disp->pior.nr) {
			ret = func->pior.new(&disp->base, i);
			if (ret)
				return ret;
		}
126 127
	}

128 129 130 131
	disp->sor.nr = func->sor.cnt(&disp->base, &disp->sor.mask);
	nvkm_debug(subdev, "   SOR(s): %d (%02lx)\n",
		   disp->sor.nr, disp->sor.mask);
	for_each_set_bit(i, &disp->sor.mask, disp->sor.nr) {
132 133 134 135 136
		ret = func->sor.new(&disp->base, i);
		if (ret)
			return ret;
	}

137 138 139 140 141
	ret = nvkm_gpuobj_new(device, 0x10000, 0x10000, false, NULL,
			      &disp->inst);
	if (ret)
		return ret;

142 143
	return nvkm_ramht_new(device, func->ramht_size ? func->ramht_size :
			      0x1000, 0, disp->inst, &disp->ramht);
144 145
}

146 147 148
static const struct nvkm_disp_func
nv50_disp_ = {
	.dtor = nv50_disp_dtor_,
149
	.oneinit = nv50_disp_oneinit_,
150 151
	.init = nv50_disp_init_,
	.fini = nv50_disp_fini_,
152 153
	.intr = nv50_disp_intr_,
	.root = nv50_disp_root_,
154 155
};

156 157
int
nv50_disp_new_(const struct nv50_disp_func *func, struct nvkm_device *device,
158
	       int index, struct nvkm_disp **pdisp)
159 160
{
	struct nv50_disp *disp;
161
	int ret;
162 163 164 165 166 167

	if (!(disp = kzalloc(sizeof(*disp), GFP_KERNEL)))
		return -ENOMEM;
	disp->func = func;
	*pdisp = &disp->base;

168
	ret = nvkm_disp_ctor(&nv50_disp_, device, index, &disp->base);
169 170 171
	if (ret)
		return ret;

172 173 174
	disp->wq = create_singlethread_workqueue("nvkm-disp");
	if (!disp->wq)
		return -ENOMEM;
175

176
	INIT_WORK(&disp->supervisor, func->super);
177

178 179
	return nvkm_event_init(func->uevent, 1, ARRAY_SIZE(disp->chan),
			       &disp->uevent);
180 181
}

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
static u32
nv50_disp_super_iedt(struct nvkm_head *head, struct nvkm_outp *outp,
		     u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
		     struct nvbios_outp *iedt)
{
	struct nvkm_bios *bios = head->disp->engine.subdev.device->bios;
	const u8  l = ffs(outp->info.link);
	const u16 t = outp->info.hasht;
	const u16 m = (0x0100 << head->id) | (l << 6) | outp->info.or;
	u32 data = nvbios_outp_match(bios, t, m, ver, hdr, cnt, len, iedt);
	if (!data)
		OUTP_DBG(outp, "missing IEDT for %04x:%04x", t, m);
	return data;
}

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
static void
nv50_disp_super_ied_on(struct nvkm_head *head,
		       struct nvkm_ior *ior, int id, u32 khz)
{
	struct nvkm_subdev *subdev = &head->disp->engine.subdev;
	struct nvkm_bios *bios = subdev->device->bios;
	struct nvkm_outp *outp = ior->asy.outp;
	struct nvbios_ocfg iedtrs;
	struct nvbios_outp iedt;
	u8  ver, hdr, cnt, len, flags = 0x00;
	u32 data;

	if (!outp) {
		IOR_DBG(ior, "nothing to attach");
		return;
	}

	/* Lookup IED table for the device. */
	data = nv50_disp_super_iedt(head, outp, &ver, &hdr, &cnt, &len, &iedt);
	if (!data)
		return;

	/* Lookup IEDT runtime settings for the current configuration. */
	if (ior->type == SOR) {
		if (ior->asy.proto == LVDS) {
			if (head->asy.or.depth == 24)
				flags |= 0x02;
		}
		if (ior->asy.link == 3)
			flags |= 0x01;
	}

	data = nvbios_ocfg_match(bios, data, ior->asy.proto_evo, flags,
				 &ver, &hdr, &cnt, &len, &iedtrs);
	if (!data) {
		OUTP_DBG(outp, "missing IEDT RS for %02x:%02x",
			 ior->asy.proto_evo, flags);
		return;
	}

	/* Execute the OnInt[23] script for the current frequency. */
	data = nvbios_oclk_match(bios, iedtrs.clkcmp[id], khz);
	if (!data) {
		OUTP_DBG(outp, "missing IEDT RSS %d for %02x:%02x %d khz",
			 id, ior->asy.proto_evo, flags, khz);
		return;
	}

	nvbios_init(subdev, data,
		init.outp = &outp->info;
		init.or   = ior->id;
		init.link = ior->asy.link;
		init.head = head->id;
	);
}

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
static void
nv50_disp_super_ied_off(struct nvkm_head *head, struct nvkm_ior *ior, int id)
{
	struct nvkm_outp *outp = ior->arm.outp;
	struct nvbios_outp iedt;
	u8  ver, hdr, cnt, len;
	u32 data;

	if (!outp) {
		IOR_DBG(ior, "nothing attached");
		return;
	}

	data = nv50_disp_super_iedt(head, outp, &ver, &hdr, &cnt, &len, &iedt);
	if (!data)
		return;

	nvbios_init(&head->disp->engine.subdev, iedt.script[id],
		init.outp = &outp->info;
		init.or   = ior->id;
		init.link = ior->arm.link;
		init.head = head->id;
	);
}

278 279 280 281 282 283 284 285 286 287 288 289 290 291
static struct nvkm_ior *
nv50_disp_super_ior_asy(struct nvkm_head *head)
{
	struct nvkm_ior *ior;
	list_for_each_entry(ior, &head->disp->ior, head) {
		if (ior->asy.head & (1 << head->id)) {
			HEAD_DBG(head, "to %s", ior->name);
			return ior;
		}
	}
	HEAD_DBG(head, "nothing to attach");
	return NULL;
}

292 293 294 295 296 297 298 299 300 301 302 303 304 305
static struct nvkm_ior *
nv50_disp_super_ior_arm(struct nvkm_head *head)
{
	struct nvkm_ior *ior;
	list_for_each_entry(ior, &head->disp->ior, head) {
		if (ior->arm.head & (1 << head->id)) {
			HEAD_DBG(head, "on %s", ior->name);
			return ior;
		}
	}
	HEAD_DBG(head, "nothing attached");
	return NULL;
}

306 307
void
nv50_disp_super_3_0(struct nv50_disp *disp, struct nvkm_head *head)
308
{
309
	struct nvkm_ior *ior;
310

311 312 313 314
	/* Determine which OR, if any, we're attaching to the head. */
	HEAD_DBG(head, "supervisor 3.0");
	ior = nv50_disp_super_ior_asy(head);
	if (!ior)
315 316
		return;

317 318 319 320 321 322
	/* Execute OnInt3 IED script. */
	nv50_disp_super_ied_on(head, ior, 1, head->asy.hz / 1000);

	/* OR-specific handling. */
	if (ior->func->war_3)
		ior->func->war_3(ior);
323 324 325
}

static void
326
nv50_disp_super_2_2_dp(struct nvkm_head *head, struct nvkm_ior *ior)
327
{
328 329 330 331
	struct nvkm_subdev *subdev = &head->disp->engine.subdev;
	const u32      khz = head->asy.hz / 1000;
	const u32 linkKBps = ior->dp.bw * 27000;
	const u32   symbol = 100000;
332 333 334 335
	int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
	int TU, VTUi, VTUf, VTUa;
	u64 link_data_rate, link_ratio, unk;
	u32 best_diff = 64 * symbol;
336
	u64 h, v;
337 338

	/* symbols/hblank - algorithm taken from comments in tegra driver */
339 340 341 342
	h = head->asy.hblanke + head->asy.htotal - head->asy.hblanks - 7;
	h = h * linkKBps;
	do_div(h, khz);
	h = h - (3 * ior->dp.ef) - (12 / ior->dp.nr);
343 344

	/* symbols/vblank - algorithm taken from comments in tegra driver */
345 346 347 348
	v = head->asy.vblanks - head->asy.vblanke - 25;
	v = v * linkKBps;
	do_div(v, khz);
	v = v - ((36 / ior->dp.nr) + 3) - 1;
349

350
	ior->func->dp.audio_sym(ior, head->id, h, v);
351

352 353
	/* watermark / activesym */
	link_data_rate = (khz * head->asy.or.depth / 8) / ior->dp.nr;
354 355 356

	/* calculate ratio of packed data rate to link symbol rate */
	link_ratio = link_data_rate * symbol;
357
	do_div(link_ratio, linkKBps);
358

359
	for (TU = 64; ior->func->dp.activesym && TU >= 32; TU--) {
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
		/* calculate average number of valid symbols in each TU */
		u32 tu_valid = link_ratio * TU;
		u32 calc, diff;

		/* find a hw representation for the fraction.. */
		VTUi = tu_valid / symbol;
		calc = VTUi * symbol;
		diff = tu_valid - calc;
		if (diff) {
			if (diff >= (symbol / 2)) {
				VTUf = symbol / (symbol - diff);
				if (symbol - (VTUf * diff))
					VTUf++;

				if (VTUf <= 15) {
					VTUa  = 1;
					calc += symbol - (symbol / VTUf);
				} else {
					VTUa  = 0;
					VTUf  = 1;
					calc += symbol;
				}
			} else {
				VTUa  = 0;
				VTUf  = min((int)(symbol / diff), 15);
				calc += symbol / VTUf;
			}

			diff = calc - tu_valid;
		} else {
			/* no remainder, but the hw doesn't like the fractional
			 * part to be zero.  decrement the integer part and
			 * have the fraction add a whole symbol back
			 */
			VTUa = 0;
			VTUf = 1;
			VTUi--;
		}

		if (diff < best_diff) {
			best_diff = diff;
			bestTU = TU;
			bestVTUa = VTUa;
			bestVTUf = VTUf;
			bestVTUi = VTUi;
			if (diff == 0)
				break;
		}
	}

410 411 412 413 414 415 416 417 418
	if (ior->func->dp.activesym) {
		if (!bestTU) {
			nvkm_error(subdev, "unable to determine dp config\n");
			return;
		}
		ior->func->dp.activesym(ior, head->id, bestTU,
					bestVTUa, bestVTUf, bestVTUi);
	} else {
		bestTU = 64;
419 420 421 422 423
	}

	/* XXX close to vbios numbers, but not right */
	unk  = (symbol - link_ratio) * bestTU;
	unk *= link_ratio;
B
Ben Skeggs 已提交
424 425
	do_div(unk, symbol);
	do_div(unk, symbol);
426 427
	unk += 6;

428
	ior->func->dp.watermark(ior, head->id, unk);
429 430
}

431 432
void
nv50_disp_super_2_2(struct nv50_disp *disp, struct nvkm_head *head)
433
{
434 435 436
	const u32 khz = head->asy.hz / 1000;
	struct nvkm_outp *outp;
	struct nvkm_ior *ior;
437

438 439 440 441
	/* Determine which OR, if any, we're attaching from the head. */
	HEAD_DBG(head, "supervisor 2.2");
	ior = nv50_disp_super_ior_asy(head);
	if (!ior)
442
		return;
443

444
	/* For some reason, NVIDIA decided not to:
445
	 *
446 447 448
	 * A) Give dual-link LVDS a separate EVO protocol, like for TMDS.
	 *  and
	 * B) Use SetControlOutputResource.PixelDepth on LVDS.
449
	 *
450 451
	 * Override the values we usually read from HW with the same
	 * data we pass though an ioctl instead.
452
	 */
453 454 455
	if (ior->type == SOR && ior->asy.proto == LVDS) {
		head->asy.or.depth = (disp->sor.lvdsconf & 0x0200) ? 24 : 18;
		ior->asy.link      = (disp->sor.lvdsconf & 0x0100) ? 3  : 1;
456 457
	}

458 459 460
	/* Handle any link training, etc. */
	if ((outp = ior->asy.outp) && outp->func->acquire)
		outp->func->acquire(outp);
461

462 463 464 465 466
	/* Execute OnInt2 IED script. */
	nv50_disp_super_ied_on(head, ior, 0, khz);

	/* Program RG clock divider. */
	head->func->rgclk(head, ior->asy.rgdiv);
467

468 469 470
	/* Mode-specific internal DP configuration. */
	if (ior->type == SOR && ior->asy.proto == DP)
		nv50_disp_super_2_2_dp(head, ior);
471

472 473 474 475
	/* OR-specific handling. */
	ior->func->clock(ior);
	if (ior->func->war_2)
		ior->func->war_2(ior);
476 477
}

478 479
void
nv50_disp_super_2_1(struct nv50_disp *disp, struct nvkm_head *head)
480
{
481
	struct nvkm_devinit *devinit = disp->base.engine.subdev.device->devinit;
482
	const u32 khz = head->asy.hz / 1000;
483 484 485
	HEAD_DBG(head, "supervisor 2.1 - %d khz", khz);
	if (khz)
		nvkm_devinit_pll_set(devinit, PLL_VPLL0 + head->id, khz);
486 487
}

488 489
void
nv50_disp_super_2_0(struct nv50_disp *disp, struct nvkm_head *head)
490
{
491 492 493 494 495 496 497 498 499 500 501 502 503
	struct nvkm_outp *outp;
	struct nvkm_ior *ior;

	/* Determine which OR, if any, we're detaching from the head. */
	HEAD_DBG(head, "supervisor 2.0");
	ior = nv50_disp_super_ior_arm(head);
	if (!ior)
		return;

	/* Execute OffInt2 IED script. */
	nv50_disp_super_ied_off(head, ior, 2);

	/* If we're shutting down the OR's only active head, execute
504
	 * the output path's disable function.
505
	 */
506
	if (ior->arm.head == (1 << head->id)) {
507 508
		if ((outp = ior->arm.outp) && outp->func->disable)
			outp->func->disable(outp, ior);
509 510 511
	}
}

512 513
void
nv50_disp_super_1_0(struct nv50_disp *disp, struct nvkm_head *head)
514
{
515 516 517 518 519 520 521 522 523 524
	struct nvkm_ior *ior;

	/* Determine which OR, if any, we're detaching from the head. */
	HEAD_DBG(head, "supervisor 1.0");
	ior = nv50_disp_super_ior_arm(head);
	if (!ior)
		return;

	/* Execute OffInt1 IED script. */
	nv50_disp_super_ied_off(head, ior, 1);
525 526
}

527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
void
nv50_disp_super_1(struct nv50_disp *disp)
{
	struct nvkm_head *head;
	struct nvkm_ior *ior;

	list_for_each_entry(head, &disp->base.head, head) {
		head->func->state(head, &head->arm);
		head->func->state(head, &head->asy);
	}

	list_for_each_entry(ior, &disp->base.ior, head) {
		ior->func->state(ior, &ior->arm);
		ior->func->state(ior, &ior->asy);
	}
}

544
void
545
nv50_disp_super(struct work_struct *work)
546
{
B
Ben Skeggs 已提交
547 548
	struct nv50_disp *disp =
		container_of(work, struct nv50_disp, supervisor);
549 550
	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
	struct nvkm_device *device = subdev->device;
551
	struct nvkm_head *head;
552
	u32 super = nvkm_rd32(device, 0x610030);
553

554
	nvkm_debug(subdev, "supervisor %08x %08x\n", disp->super, super);
555

B
Ben Skeggs 已提交
556
	if (disp->super & 0x00000010) {
557
		nv50_disp_chan_mthd(disp->chan[0], NV_DBG_DEBUG);
558
		nv50_disp_super_1(disp);
559 560
		list_for_each_entry(head, &disp->base.head, head) {
			if (!(super & (0x00000020 << head->id)))
561
				continue;
562
			if (!(super & (0x00000080 << head->id)))
563
				continue;
564
			nv50_disp_super_1_0(disp, head);
565 566
		}
	} else
B
Ben Skeggs 已提交
567
	if (disp->super & 0x00000020) {
568 569
		list_for_each_entry(head, &disp->base.head, head) {
			if (!(super & (0x00000080 << head->id)))
570
				continue;
571
			nv50_disp_super_2_0(disp, head);
572
		}
573
		nvkm_outp_route(&disp->base);
574 575
		list_for_each_entry(head, &disp->base.head, head) {
			if (!(super & (0x00000200 << head->id)))
576
				continue;
577
			nv50_disp_super_2_1(disp, head);
578
		}
579 580
		list_for_each_entry(head, &disp->base.head, head) {
			if (!(super & (0x00000080 << head->id)))
581
				continue;
582
			nv50_disp_super_2_2(disp, head);
583 584
		}
	} else
B
Ben Skeggs 已提交
585
	if (disp->super & 0x00000040) {
586 587
		list_for_each_entry(head, &disp->base.head, head) {
			if (!(super & (0x00000080 << head->id)))
588
				continue;
589
			nv50_disp_super_3_0(disp, head);
590 591 592
		}
	}

593
	nvkm_wr32(device, 0x610030, 0x80000000);
594 595
}

596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644
static const struct nvkm_enum
nv50_disp_intr_error_type[] = {
	{ 3, "ILLEGAL_MTHD" },
	{ 4, "INVALID_VALUE" },
	{ 5, "INVALID_STATE" },
	{ 7, "INVALID_HANDLE" },
	{}
};

static const struct nvkm_enum
nv50_disp_intr_error_code[] = {
	{ 0x00, "" },
	{}
};

static void
nv50_disp_intr_error(struct nv50_disp *disp, int chid)
{
	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
	struct nvkm_device *device = subdev->device;
	u32 data = nvkm_rd32(device, 0x610084 + (chid * 0x08));
	u32 addr = nvkm_rd32(device, 0x610080 + (chid * 0x08));
	u32 code = (addr & 0x00ff0000) >> 16;
	u32 type = (addr & 0x00007000) >> 12;
	u32 mthd = (addr & 0x00000ffc);
	const struct nvkm_enum *ec, *et;

	et = nvkm_enum_find(nv50_disp_intr_error_type, type);
	ec = nvkm_enum_find(nv50_disp_intr_error_code, code);

	nvkm_error(subdev,
		   "ERROR %d [%s] %02x [%s] chid %d mthd %04x data %08x\n",
		   type, et ? et->name : "", code, ec ? ec->name : "",
		   chid, mthd, data);

	if (chid < ARRAY_SIZE(disp->chan)) {
		switch (mthd) {
		case 0x0080:
			nv50_disp_chan_mthd(disp->chan[chid], NV_DBG_ERROR);
			break;
		default:
			break;
		}
	}

	nvkm_wr32(device, 0x610020, 0x00010000 << chid);
	nvkm_wr32(device, 0x610080 + (chid * 0x08), 0x90000000);
}

645
void
646
nv50_disp_intr(struct nv50_disp *disp)
647
{
648 649 650
	struct nvkm_device *device = disp->base.engine.subdev.device;
	u32 intr0 = nvkm_rd32(device, 0x610020);
	u32 intr1 = nvkm_rd32(device, 0x610024);
651

652 653
	while (intr0 & 0x001f0000) {
		u32 chid = __ffs(intr0 & 0x001f0000) - 16;
B
Ben Skeggs 已提交
654
		nv50_disp_intr_error(disp, chid);
655
		intr0 &= ~(0x00010000 << chid);
656 657
	}

658 659
	while (intr0 & 0x0000001f) {
		u32 chid = __ffs(intr0 & 0x0000001f);
B
Ben Skeggs 已提交
660
		nv50_disp_chan_uevent_send(disp, chid);
661 662 663
		intr0 &= ~(0x00000001 << chid);
	}

664
	if (intr1 & 0x00000004) {
B
Ben Skeggs 已提交
665
		nvkm_disp_vblank(&disp->base, 0);
666
		nvkm_wr32(device, 0x610024, 0x00000004);
667 668
	}

669
	if (intr1 & 0x00000008) {
B
Ben Skeggs 已提交
670
		nvkm_disp_vblank(&disp->base, 1);
671
		nvkm_wr32(device, 0x610024, 0x00000008);
672 673
	}

674
	if (intr1 & 0x00000070) {
B
Ben Skeggs 已提交
675
		disp->super = (intr1 & 0x00000070);
676
		queue_work(disp->wq, &disp->supervisor);
677
		nvkm_wr32(device, 0x610024, disp->super);
678
	}
679 680
}

681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
void
nv50_disp_fini(struct nv50_disp *disp)
{
	struct nvkm_device *device = disp->base.engine.subdev.device;
	/* disable all interrupts */
	nvkm_wr32(device, 0x610024, 0x00000000);
	nvkm_wr32(device, 0x610020, 0x00000000);
}

int
nv50_disp_init(struct nv50_disp *disp)
{
	struct nvkm_device *device = disp->base.engine.subdev.device;
	struct nvkm_head *head;
	u32 tmp;
	int i;

	/* The below segments of code copying values from one register to
	 * another appear to inform EVO of the display capabilities or
	 * something similar.  NFI what the 0x614004 caps are for..
	 */
	tmp = nvkm_rd32(device, 0x614004);
	nvkm_wr32(device, 0x610184, tmp);

	/* ... CRTC caps */
	list_for_each_entry(head, &disp->base.head, head) {
		tmp = nvkm_rd32(device, 0x616100 + (head->id * 0x800));
		nvkm_wr32(device, 0x610190 + (head->id * 0x10), tmp);
		tmp = nvkm_rd32(device, 0x616104 + (head->id * 0x800));
		nvkm_wr32(device, 0x610194 + (head->id * 0x10), tmp);
		tmp = nvkm_rd32(device, 0x616108 + (head->id * 0x800));
		nvkm_wr32(device, 0x610198 + (head->id * 0x10), tmp);
		tmp = nvkm_rd32(device, 0x61610c + (head->id * 0x800));
		nvkm_wr32(device, 0x61019c + (head->id * 0x10), tmp);
	}

	/* ... DAC caps */
	for (i = 0; i < disp->dac.nr; i++) {
		tmp = nvkm_rd32(device, 0x61a000 + (i * 0x800));
		nvkm_wr32(device, 0x6101d0 + (i * 0x04), tmp);
	}

	/* ... SOR caps */
	for (i = 0; i < disp->sor.nr; i++) {
		tmp = nvkm_rd32(device, 0x61c000 + (i * 0x800));
		nvkm_wr32(device, 0x6101e0 + (i * 0x04), tmp);
	}

	/* ... PIOR caps */
	for (i = 0; i < disp->pior.nr; i++) {
		tmp = nvkm_rd32(device, 0x61e000 + (i * 0x800));
		nvkm_wr32(device, 0x6101f0 + (i * 0x04), tmp);
	}

	/* steal display away from vbios, or something like that */
	if (nvkm_rd32(device, 0x610024) & 0x00000100) {
		nvkm_wr32(device, 0x610024, 0x00000100);
		nvkm_mask(device, 0x6194e8, 0x00000001, 0x00000000);
		if (nvkm_msec(device, 2000,
			if (!(nvkm_rd32(device, 0x6194e8) & 0x00000002))
				break;
		) < 0)
			return -EBUSY;
	}

	/* point at display engine memory area (hash table, objects) */
	nvkm_wr32(device, 0x610010, (disp->inst->addr >> 8) | 9);

	/* enable supervisor interrupts, disable everything else */
	nvkm_wr32(device, 0x61002c, 0x00000370);
	nvkm_wr32(device, 0x610028, 0x00000000);
	return 0;
}

755
static const struct nv50_disp_func
756
nv50_disp = {
757 758
	.init = nv50_disp_init,
	.fini = nv50_disp_fini,
759 760
	.intr = nv50_disp_intr,
	.uevent = &nv50_disp_chan_uevent,
761
	.super = nv50_disp_super,
762
	.root = &nv50_disp_root_oclass,
763
	.head = { .cnt = nv50_head_cnt, .new = nv50_head_new },
764
	.dac = { .cnt = nv50_dac_cnt, .new = nv50_dac_new },
765
	.sor = { .cnt = nv50_sor_cnt, .new = nv50_sor_new },
766
	.pior = { .cnt = nv50_pior_cnt, .new = nv50_pior_new },
767 768
};

769 770
int
nv50_disp_new(struct nvkm_device *device, int index, struct nvkm_disp **pdisp)
771
{
772
	return nv50_disp_new_(&nv50_disp, device, index, pdisp);
773
}