rootnv50.c 13.0 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 25 26 27 28 29 30 31
/*
 * 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
 */
#include "rootnv50.h"
#include "dmacnv50.h"

#include <core/client.h>
#include <core/ramht.h>
#include <subdev/timer.h>

#include <nvif/class.h>
32
#include <nvif/cl5070.h>
33 34 35 36 37 38 39 40 41 42
#include <nvif/unpack.h>

int
nv50_disp_root_scanoutpos(NV50_DISP_MTHD_V0)
{
	struct nvkm_device *device = disp->base.engine.subdev.device;
	const u32 blanke = nvkm_rd32(device, 0x610aec + (head * 0x540));
	const u32 blanks = nvkm_rd32(device, 0x610af4 + (head * 0x540));
	const u32 total  = nvkm_rd32(device, 0x610afc + (head * 0x540));
	union {
43
		struct nv50_disp_scanoutpos_v0 v0;
44
	} *args = data;
45
	int ret = -ENOSYS;
46 47

	nvif_ioctl(object, "disp scanoutpos size %d\n", size);
48
	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
		nvif_ioctl(object, "disp scanoutpos vers %d\n",
			   args->v0.version);
		args->v0.vblanke = (blanke & 0xffff0000) >> 16;
		args->v0.hblanke = (blanke & 0x0000ffff);
		args->v0.vblanks = (blanks & 0xffff0000) >> 16;
		args->v0.hblanks = (blanks & 0x0000ffff);
		args->v0.vtotal  = ( total & 0xffff0000) >> 16;
		args->v0.htotal  = ( total & 0x0000ffff);
		args->v0.time[0] = ktime_to_ns(ktime_get());
		args->v0.vline = /* vline read locks hline */
			nvkm_rd32(device, 0x616340 + (head * 0x800)) & 0xffff;
		args->v0.time[1] = ktime_to_ns(ktime_get());
		args->v0.hline =
			nvkm_rd32(device, 0x616344 + (head * 0x800)) & 0xffff;
	} else
		return ret;

	return 0;
}

69
static int
70
nv50_disp_root_mthd_(struct nvkm_object *object, u32 mthd, void *data, u32 size)
71 72 73 74 75
{
	union {
		struct nv50_disp_mthd_v0 v0;
		struct nv50_disp_mthd_v1 v1;
	} *args = data;
76 77
	struct nv50_disp_root *root = nv50_disp_root(object);
	struct nv50_disp *disp = root->disp;
78
	const struct nv50_disp_func *func = disp->func;
79 80 81
	struct nvkm_output *outp = NULL;
	struct nvkm_output *temp;
	u16 type, mask = 0;
82
	int head, ret = -ENOSYS;
83 84 85 86 87

	if (mthd != NV50_DISP_MTHD)
		return -EINVAL;

	nvif_ioctl(object, "disp mthd size %d\n", size);
88
	if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, true))) {
89 90 91 92 93
		nvif_ioctl(object, "disp mthd vers %d mthd %02x head %d\n",
			   args->v0.version, args->v0.method, args->v0.head);
		mthd = args->v0.method;
		head = args->v0.head;
	} else
94
	if (!(ret = nvif_unpack(ret, &data, &size, args->v1, 1, 1, true))) {
95 96 97 98 99 100 101 102 103 104 105
		nvif_ioctl(object, "disp mthd vers %d mthd %02x "
				   "type %04x mask %04x\n",
			   args->v1.version, args->v1.method,
			   args->v1.hasht, args->v1.hashm);
		mthd = args->v1.method;
		type = args->v1.hasht;
		mask = args->v1.hashm;
		head = ffs((mask >> 8) & 0x0f) - 1;
	} else
		return ret;

106
	if (head < 0 || head >= disp->base.head.nr)
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
		return -ENXIO;

	if (mask) {
		list_for_each_entry(temp, &disp->base.outp, head) {
			if ((temp->info.hasht         == type) &&
			    (temp->info.hashm & mask) == mask) {
				outp = temp;
				break;
			}
		}
		if (outp == NULL)
			return -ENXIO;
	}

	switch (mthd) {
	case NV50_DISP_SCANOUTPOS:
123
		return func->head.scanoutpos(object, disp, data, size, head);
124 125 126 127 128 129
	default:
		break;
	}

	switch (mthd * !!outp) {
	case NV50_DISP_MTHD_V1_DAC_PWR:
130
		return func->dac.power(object, disp, data, size, head, outp);
131
	case NV50_DISP_MTHD_V1_DAC_LOAD:
132
		return func->dac.sense(object, disp, data, size, head, outp);
133
	case NV50_DISP_MTHD_V1_SOR_PWR:
134
		return func->sor.power(object, disp, data, size, head, outp);
135
	case NV50_DISP_MTHD_V1_SOR_HDA_ELD:
136
		if (!func->sor.hda_eld)
137
			return -ENODEV;
138
		return func->sor.hda_eld(object, disp, data, size, head, outp);
139
	case NV50_DISP_MTHD_V1_SOR_HDMI_PWR:
140
		if (!func->sor.hdmi)
141
			return -ENODEV;
142
		return func->sor.hdmi(object, disp, data, size, head, outp);
143 144 145 146
	case NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT: {
		union {
			struct nv50_disp_sor_lvds_script_v0 v0;
		} *args = data;
147
		int ret = -ENOSYS;
148
		nvif_ioctl(object, "disp sor lvds script size %d\n", size);
149
		if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
150 151 152 153 154 155 156 157 158 159 160 161 162 163
			nvif_ioctl(object, "disp sor lvds script "
					   "vers %d name %04x\n",
				   args->v0.version, args->v0.script);
			disp->sor.lvdsconf = args->v0.script;
			return 0;
		} else
			return ret;
	}
		break;
	case NV50_DISP_MTHD_V1_SOR_DP_PWR: {
		struct nvkm_output_dp *outpdp = nvkm_output_dp(outp);
		union {
			struct nv50_disp_sor_dp_pwr_v0 v0;
		} *args = data;
164
		int ret = -ENOSYS;
165
		nvif_ioctl(object, "disp sor dp pwr size %d\n", size);
166
		if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
167 168 169 170 171 172 173 174 175
			nvif_ioctl(object, "disp sor dp pwr vers %d state %d\n",
				   args->v0.version, args->v0.state);
			if (args->v0.state == 0) {
				nvkm_notify_put(&outpdp->irq);
				outpdp->func->lnk_pwr(outpdp, 0);
				atomic_set(&outpdp->lt.done, 0);
				return 0;
			} else
			if (args->v0.state != 0) {
176
				nvkm_output_dp_train(&outpdp->base, 0);
177 178 179 180 181 182
				return 0;
			}
		} else
			return ret;
	}
		break;
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
	case NV50_DISP_MTHD_V1_SOR_DP_MST_LINK: {
		struct nvkm_output_dp *outpdp = nvkm_output_dp(outp);
		union {
			struct nv50_disp_sor_dp_mst_link_v0 v0;
		} *args = data;
		int ret = -ENOSYS;
		nvif_ioctl(object, "disp sor dp mst link size %d\n", size);
		if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
			nvif_ioctl(object, "disp sor dp mst link vers %d state %d\n",
				   args->v0.version, args->v0.state);
			if (outpdp->lt.mst != !!args->v0.state) {
				outpdp->lt.mst = !!args->v0.state;
				atomic_set(&outpdp->lt.done, 0);
				nvkm_output_dp_train(&outpdp->base, 0);
			}
			return 0;
		} else
			return ret;
	}
		break;
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
	case NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI: {
		struct nvkm_output_dp *outpdp = nvkm_output_dp(outp);
		union {
			struct nv50_disp_sor_dp_mst_vcpi_v0 v0;
		} *args = data;
		int ret = -ENOSYS;
		nvif_ioctl(object, "disp sor dp mst vcpi size %d\n", size);
		if (!(ret = nvif_unpack(ret, &data, &size, args->v0, 0, 0, false))) {
			nvif_ioctl(object, "disp sor dp mst vcpi vers %d "
					   "slot %02x/%02x pbn %04x/%04x\n",
				   args->v0.version, args->v0.start_slot,
				   args->v0.num_slots, args->v0.pbn,
				   args->v0.aligned_pbn);
			if (!outpdp->func->vcpi)
				return -ENODEV;
			outpdp->func->vcpi(outpdp, head, args->v0.start_slot,
					   args->v0.num_slots, args->v0.pbn,
					   args->v0.aligned_pbn);
			return 0;
		} else
			return ret;
	}
		break;
226
	case NV50_DISP_MTHD_V1_PIOR_PWR:
227
		if (!func->pior.power)
228
			return -ENODEV;
229
		return func->pior.power(object, disp, data, size, head, outp);
230 231 232 233 234 235 236
	default:
		break;
	}

	return -EINVAL;
}

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
static int
nv50_disp_root_dmac_new_(const struct nvkm_oclass *oclass,
			 void *data, u32 size, struct nvkm_object **pobject)
{
	const struct nv50_disp_dmac_oclass *sclass = oclass->priv;
	struct nv50_disp_root *root = nv50_disp_root(oclass->parent);
	return sclass->ctor(sclass->func, sclass->mthd, root, sclass->chid,
			    oclass, data, size, pobject);
}

static int
nv50_disp_root_pioc_new_(const struct nvkm_oclass *oclass,
			 void *data, u32 size, struct nvkm_object **pobject)
{
	const struct nv50_disp_pioc_oclass *sclass = oclass->priv;
	struct nv50_disp_root *root = nv50_disp_root(oclass->parent);
253 254
	return sclass->ctor(sclass->func, sclass->mthd, root, sclass->chid.ctrl,
			    sclass->chid.user, oclass, data, size, pobject);
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
}

static int
nv50_disp_root_child_get_(struct nvkm_object *object, int index,
			  struct nvkm_oclass *sclass)
{
	struct nv50_disp_root *root = nv50_disp_root(object);

	if (index < ARRAY_SIZE(root->func->dmac)) {
		sclass->base = root->func->dmac[index]->base;
		sclass->priv = root->func->dmac[index];
		sclass->ctor = nv50_disp_root_dmac_new_;
		return 0;
	}

	index -= ARRAY_SIZE(root->func->dmac);

	if (index < ARRAY_SIZE(root->func->pioc)) {
		sclass->base = root->func->pioc[index]->base;
		sclass->priv = root->func->pioc[index];
		sclass->ctor = nv50_disp_root_pioc_new_;
		return 0;
	}

	return -EINVAL;
}

static int
nv50_disp_root_fini_(struct nvkm_object *object, bool suspend)
{
	struct nv50_disp_root *root = nv50_disp_root(object);
	root->func->fini(root);
	return 0;
}

static int
nv50_disp_root_init_(struct nvkm_object *object)
{
	struct nv50_disp_root *root = nv50_disp_root(object);
	return root->func->init(root);
}

static void *
nv50_disp_root_dtor_(struct nvkm_object *object)
{
	struct nv50_disp_root *root = nv50_disp_root(object);
	nvkm_ramht_del(&root->ramht);
	nvkm_gpuobj_del(&root->instmem);
	return root;
}

static const struct nvkm_object_func
nv50_disp_root_ = {
	.dtor = nv50_disp_root_dtor_,
	.init = nv50_disp_root_init_,
	.fini = nv50_disp_root_fini_,
	.mthd = nv50_disp_root_mthd_,
	.ntfy = nvkm_disp_ntfy,
	.sclass = nv50_disp_root_child_get_,
};

316
int
317 318 319
nv50_disp_root_new_(const struct nv50_disp_root_func *func,
		    struct nvkm_disp *base, const struct nvkm_oclass *oclass,
		    void *data, u32 size, struct nvkm_object **pobject)
320
{
321
	struct nv50_disp *disp = nv50_disp(base);
322 323 324 325
	struct nv50_disp_root *root;
	struct nvkm_device *device = disp->base.engine.subdev.device;
	int ret;

326 327 328 329 330 331 332 333 334 335
	if (!(root = kzalloc(sizeof(*root), GFP_KERNEL)))
		return -ENOMEM;
	*pobject = &root->object;

	nvkm_object_ctor(&nv50_disp_root_, oclass, &root->object);
	root->func = func;
	root->disp = disp;

	ret = nvkm_gpuobj_new(disp->base.engine.subdev.device, 0x10000, 0x10000,
			      false, NULL, &root->instmem);
336 337 338
	if (ret)
		return ret;

339
	return nvkm_ramht_new(device, 0x1000, 0, root->instmem, &root->ramht);
340 341 342
}

void
343
nv50_disp_root_fini(struct nv50_disp_root *root)
344
{
345 346 347 348
	struct nvkm_device *device = root->disp->base.engine.subdev.device;
	/* disable all interrupts */
	nvkm_wr32(device, 0x610024, 0x00000000);
	nvkm_wr32(device, 0x610020, 0x00000000);
349 350
}

351 352
int
nv50_disp_root_init(struct nv50_disp_root *root)
353
{
354
	struct nv50_disp *disp = root->disp;
355 356
	struct nvkm_device *device = disp->base.engine.subdev.device;
	u32 tmp;
357
	int i;
358 359 360 361 362 363 364 365 366

	/* 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 */
367
	for (i = 0; i < disp->base.head.nr; i++) {
368 369 370 371 372 373 374 375 376 377 378
		tmp = nvkm_rd32(device, 0x616100 + (i * 0x800));
		nvkm_wr32(device, 0x610190 + (i * 0x10), tmp);
		tmp = nvkm_rd32(device, 0x616104 + (i * 0x800));
		nvkm_wr32(device, 0x610194 + (i * 0x10), tmp);
		tmp = nvkm_rd32(device, 0x616108 + (i * 0x800));
		nvkm_wr32(device, 0x610198 + (i * 0x10), tmp);
		tmp = nvkm_rd32(device, 0x61610c + (i * 0x800));
		nvkm_wr32(device, 0x61019c + (i * 0x10), tmp);
	}

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

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

	/* ... PIOR caps */
391
	for (i = 0; i < disp->func->pior.nr; i++) {
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
		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) */
408
	nvkm_wr32(device, 0x610010, (root->instmem->addr >> 8) | 9);
409 410 411 412 413 414 415

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

416 417
static const struct nv50_disp_root_func
nv50_disp_root = {
418 419
	.init = nv50_disp_root_init,
	.fini = nv50_disp_root_fini,
420 421 422 423 424 425 426 427 428
	.dmac = {
		&nv50_disp_core_oclass,
		&nv50_disp_base_oclass,
		&nv50_disp_ovly_oclass,
	},
	.pioc = {
		&nv50_disp_oimm_oclass,
		&nv50_disp_curs_oclass,
	},
429 430
};

431 432 433 434 435 436 437
static int
nv50_disp_root_new(struct nvkm_disp *disp, const struct nvkm_oclass *oclass,
		   void *data, u32 size, struct nvkm_object **pobject)
{
	return nv50_disp_root_new_(&nv50_disp_root, disp, oclass,
				   data, size, pobject);
}
438

439 440 441 442 443 444
const struct nvkm_disp_oclass
nv50_disp_root_oclass = {
	.base.oclass = NV50_DISP,
	.base.minver = -1,
	.base.maxver = -1,
	.ctor = nv50_disp_root_new,
445
};