blob: c6f80055e988a2049bd1634a31c0379e1a2190ca [file] [log] [blame]
Ben Skeggsebb945a2012-07-20 08:17:34 +10001/*
2 * Copyright 2012 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
Ben Skeggs370c00f2012-08-14 14:11:49 +100025#include <core/object.h>
26#include <core/parent.h>
27#include <core/handle.h>
28#include <core/class.h>
29
Ben Skeggsebb945a2012-07-20 08:17:34 +100030#include <engine/software.h>
31#include <engine/disp.h>
32
Ben Skeggs186ecad2012-11-09 12:09:48 +100033#include <subdev/bios.h>
34#include <subdev/bios/dcb.h>
35#include <subdev/bios/disp.h>
36#include <subdev/bios/init.h>
37#include <subdev/bios/pll.h>
Ben Skeggs446b05a2012-08-14 12:50:14 +100038#include <subdev/timer.h>
Ben Skeggs370c00f2012-08-14 14:11:49 +100039#include <subdev/fb.h>
40#include <subdev/bar.h>
Ben Skeggs186ecad2012-11-09 12:09:48 +100041#include <subdev/clock.h>
Ben Skeggs446b05a2012-08-14 12:50:14 +100042
Ben Skeggs70cabe42012-08-14 10:04:04 +100043#include "nv50.h"
44
45/*******************************************************************************
Ben Skeggs370c00f2012-08-14 14:11:49 +100046 * EVO channel base class
Ben Skeggs70cabe42012-08-14 10:04:04 +100047 ******************************************************************************/
48
Ben Skeggs370c00f2012-08-14 14:11:49 +100049int
50nv50_disp_chan_create_(struct nouveau_object *parent,
51 struct nouveau_object *engine,
52 struct nouveau_oclass *oclass, int chid,
53 int length, void **pobject)
54{
55 struct nv50_disp_base *base = (void *)parent;
56 struct nv50_disp_chan *chan;
57 int ret;
58
59 if (base->chan & (1 << chid))
60 return -EBUSY;
61 base->chan |= (1 << chid);
62
63 ret = nouveau_namedb_create_(parent, engine, oclass, 0, NULL,
64 (1ULL << NVDEV_ENGINE_DMAOBJ),
65 length, pobject);
66 chan = *pobject;
67 if (ret)
68 return ret;
69
70 chan->chid = chid;
71 return 0;
72}
73
74void
75nv50_disp_chan_destroy(struct nv50_disp_chan *chan)
76{
77 struct nv50_disp_base *base = (void *)nv_object(chan)->parent;
78 base->chan &= ~(1 << chan->chid);
79 nouveau_namedb_destroy(&chan->base);
80}
81
82u32
Ben Skeggs70cabe42012-08-14 10:04:04 +100083nv50_disp_chan_rd32(struct nouveau_object *object, u64 addr)
84{
Ben Skeggs370c00f2012-08-14 14:11:49 +100085 struct nv50_disp_priv *priv = (void *)object->engine;
86 struct nv50_disp_chan *chan = (void *)object;
87 return nv_rd32(priv, 0x640000 + (chan->chid * 0x1000) + addr);
88}
89
90void
91nv50_disp_chan_wr32(struct nouveau_object *object, u64 addr, u32 data)
92{
93 struct nv50_disp_priv *priv = (void *)object->engine;
94 struct nv50_disp_chan *chan = (void *)object;
95 nv_wr32(priv, 0x640000 + (chan->chid * 0x1000) + addr, data);
96}
97
98/*******************************************************************************
99 * EVO DMA channel base class
100 ******************************************************************************/
101
102static int
103nv50_disp_dmac_object_attach(struct nouveau_object *parent,
104 struct nouveau_object *object, u32 name)
105{
106 struct nv50_disp_base *base = (void *)parent->parent;
107 struct nv50_disp_chan *chan = (void *)parent;
108 u32 addr = nv_gpuobj(object)->node->offset;
109 u32 chid = chan->chid;
110 u32 data = (chid << 28) | (addr << 10) | chid;
111 return nouveau_ramht_insert(base->ramht, chid, name, data);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000112}
113
114static void
Ben Skeggs370c00f2012-08-14 14:11:49 +1000115nv50_disp_dmac_object_detach(struct nouveau_object *parent, int cookie)
Ben Skeggs70cabe42012-08-14 10:04:04 +1000116{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000117 struct nv50_disp_base *base = (void *)parent->parent;
118 nouveau_ramht_remove(base->ramht, cookie);
119}
120
121int
122nv50_disp_dmac_create_(struct nouveau_object *parent,
123 struct nouveau_object *engine,
124 struct nouveau_oclass *oclass, u32 pushbuf, int chid,
125 int length, void **pobject)
126{
127 struct nv50_disp_dmac *dmac;
128 int ret;
129
130 ret = nv50_disp_chan_create_(parent, engine, oclass, chid,
131 length, pobject);
132 dmac = *pobject;
133 if (ret)
134 return ret;
135
136 dmac->pushdma = (void *)nouveau_handle_ref(parent, pushbuf);
137 if (!dmac->pushdma)
138 return -ENOENT;
139
140 switch (nv_mclass(dmac->pushdma)) {
141 case 0x0002:
142 case 0x003d:
143 if (dmac->pushdma->limit - dmac->pushdma->start != 0xfff)
144 return -EINVAL;
145
146 switch (dmac->pushdma->target) {
147 case NV_MEM_TARGET_VRAM:
148 dmac->push = 0x00000000 | dmac->pushdma->start >> 8;
149 break;
Ben Skeggs944234d2012-10-30 10:03:38 +1000150 case NV_MEM_TARGET_PCI_NOSNOOP:
151 dmac->push = 0x00000003 | dmac->pushdma->start >> 8;
152 break;
Ben Skeggs370c00f2012-08-14 14:11:49 +1000153 default:
154 return -EINVAL;
155 }
156 break;
157 default:
158 return -EINVAL;
159 }
160
161 return 0;
162}
163
164void
165nv50_disp_dmac_dtor(struct nouveau_object *object)
166{
167 struct nv50_disp_dmac *dmac = (void *)object;
168 nouveau_object_ref(NULL, (struct nouveau_object **)&dmac->pushdma);
169 nv50_disp_chan_destroy(&dmac->base);
170}
171
172static int
173nv50_disp_dmac_init(struct nouveau_object *object)
174{
175 struct nv50_disp_priv *priv = (void *)object->engine;
176 struct nv50_disp_dmac *dmac = (void *)object;
177 int chid = dmac->base.chid;
178 int ret;
179
180 ret = nv50_disp_chan_init(&dmac->base);
181 if (ret)
182 return ret;
183
184 /* enable error reporting */
185 nv_mask(priv, 0x610028, 0x00010001 << chid, 0x00010001 << chid);
186
187 /* initialise channel for dma command submission */
188 nv_wr32(priv, 0x610204 + (chid * 0x0010), dmac->push);
189 nv_wr32(priv, 0x610208 + (chid * 0x0010), 0x00010000);
190 nv_wr32(priv, 0x61020c + (chid * 0x0010), chid);
191 nv_mask(priv, 0x610200 + (chid * 0x0010), 0x00000010, 0x00000010);
192 nv_wr32(priv, 0x640000 + (chid * 0x1000), 0x00000000);
193 nv_wr32(priv, 0x610200 + (chid * 0x0010), 0x00000013);
194
195 /* wait for it to go inactive */
196 if (!nv_wait(priv, 0x610200 + (chid * 0x10), 0x80000000, 0x00000000)) {
197 nv_error(dmac, "init timeout, 0x%08x\n",
198 nv_rd32(priv, 0x610200 + (chid * 0x10)));
199 return -EBUSY;
200 }
201
202 return 0;
203}
204
205static int
206nv50_disp_dmac_fini(struct nouveau_object *object, bool suspend)
207{
208 struct nv50_disp_priv *priv = (void *)object->engine;
209 struct nv50_disp_dmac *dmac = (void *)object;
210 int chid = dmac->base.chid;
211
212 /* deactivate channel */
213 nv_mask(priv, 0x610200 + (chid * 0x0010), 0x00001010, 0x00001000);
214 nv_mask(priv, 0x610200 + (chid * 0x0010), 0x00000003, 0x00000000);
215 if (!nv_wait(priv, 0x610200 + (chid * 0x10), 0x001e0000, 0x00000000)) {
216 nv_error(dmac, "fini timeout, 0x%08x\n",
217 nv_rd32(priv, 0x610200 + (chid * 0x10)));
218 if (suspend)
219 return -EBUSY;
220 }
221
222 /* disable error reporting */
223 nv_mask(priv, 0x610028, 0x00010001 << chid, 0x00000000 << chid);
224
225 return nv50_disp_chan_fini(&dmac->base, suspend);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000226}
227
228/*******************************************************************************
229 * EVO master channel object
230 ******************************************************************************/
231
232static int
233nv50_disp_mast_ctor(struct nouveau_object *parent,
234 struct nouveau_object *engine,
235 struct nouveau_oclass *oclass, void *data, u32 size,
236 struct nouveau_object **pobject)
237{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000238 struct nv50_display_mast_class *args = data;
239 struct nv50_disp_dmac *mast;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000240 int ret;
241
Ben Skeggs370c00f2012-08-14 14:11:49 +1000242 if (size < sizeof(*args))
243 return -EINVAL;
244
245 ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
246 0, sizeof(*mast), (void **)&mast);
247 *pobject = nv_object(mast);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000248 if (ret)
249 return ret;
250
Ben Skeggs370c00f2012-08-14 14:11:49 +1000251 nv_parent(mast)->object_attach = nv50_disp_dmac_object_attach;
252 nv_parent(mast)->object_detach = nv50_disp_dmac_object_detach;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000253 return 0;
254}
255
Ben Skeggs70cabe42012-08-14 10:04:04 +1000256static int
257nv50_disp_mast_init(struct nouveau_object *object)
258{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000259 struct nv50_disp_priv *priv = (void *)object->engine;
260 struct nv50_disp_dmac *mast = (void *)object;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000261 int ret;
262
Ben Skeggs370c00f2012-08-14 14:11:49 +1000263 ret = nv50_disp_chan_init(&mast->base);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000264 if (ret)
265 return ret;
266
Ben Skeggs370c00f2012-08-14 14:11:49 +1000267 /* enable error reporting */
268 nv_mask(priv, 0x610028, 0x00010001, 0x00010001);
269
270 /* attempt to unstick channel from some unknown state */
271 if ((nv_rd32(priv, 0x610200) & 0x009f0000) == 0x00020000)
272 nv_mask(priv, 0x610200, 0x00800000, 0x00800000);
273 if ((nv_rd32(priv, 0x610200) & 0x003f0000) == 0x00030000)
274 nv_mask(priv, 0x610200, 0x00600000, 0x00600000);
275
276 /* initialise channel for dma command submission */
277 nv_wr32(priv, 0x610204, mast->push);
278 nv_wr32(priv, 0x610208, 0x00010000);
279 nv_wr32(priv, 0x61020c, 0x00000000);
280 nv_mask(priv, 0x610200, 0x00000010, 0x00000010);
281 nv_wr32(priv, 0x640000, 0x00000000);
282 nv_wr32(priv, 0x610200, 0x01000013);
283
284 /* wait for it to go inactive */
285 if (!nv_wait(priv, 0x610200, 0x80000000, 0x00000000)) {
286 nv_error(mast, "init: 0x%08x\n", nv_rd32(priv, 0x610200));
287 return -EBUSY;
288 }
289
Ben Skeggs70cabe42012-08-14 10:04:04 +1000290 return 0;
291}
292
293static int
294nv50_disp_mast_fini(struct nouveau_object *object, bool suspend)
295{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000296 struct nv50_disp_priv *priv = (void *)object->engine;
297 struct nv50_disp_dmac *mast = (void *)object;
298
299 /* deactivate channel */
300 nv_mask(priv, 0x610200, 0x00000010, 0x00000000);
301 nv_mask(priv, 0x610200, 0x00000003, 0x00000000);
302 if (!nv_wait(priv, 0x610200, 0x001e0000, 0x00000000)) {
303 nv_error(mast, "fini: 0x%08x\n", nv_rd32(priv, 0x610200));
304 if (suspend)
305 return -EBUSY;
306 }
307
308 /* disable error reporting */
309 nv_mask(priv, 0x610028, 0x00010001, 0x00000000);
310
311 return nv50_disp_chan_fini(&mast->base, suspend);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000312}
313
314struct nouveau_ofuncs
315nv50_disp_mast_ofuncs = {
316 .ctor = nv50_disp_mast_ctor,
Ben Skeggs370c00f2012-08-14 14:11:49 +1000317 .dtor = nv50_disp_dmac_dtor,
Ben Skeggs70cabe42012-08-14 10:04:04 +1000318 .init = nv50_disp_mast_init,
319 .fini = nv50_disp_mast_fini,
320 .rd32 = nv50_disp_chan_rd32,
321 .wr32 = nv50_disp_chan_wr32,
322};
323
324/*******************************************************************************
Ben Skeggs370c00f2012-08-14 14:11:49 +1000325 * EVO sync channel objects
Ben Skeggs70cabe42012-08-14 10:04:04 +1000326 ******************************************************************************/
327
328static int
Ben Skeggs370c00f2012-08-14 14:11:49 +1000329nv50_disp_sync_ctor(struct nouveau_object *parent,
Ben Skeggs70cabe42012-08-14 10:04:04 +1000330 struct nouveau_object *engine,
331 struct nouveau_oclass *oclass, void *data, u32 size,
332 struct nouveau_object **pobject)
333{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000334 struct nv50_display_sync_class *args = data;
335 struct nv50_disp_dmac *dmac;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000336 int ret;
337
Ben Skeggs370c00f2012-08-14 14:11:49 +1000338 if (size < sizeof(*data) || args->head > 1)
339 return -EINVAL;
340
341 ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
342 1 + args->head, sizeof(*dmac),
343 (void **)&dmac);
344 *pobject = nv_object(dmac);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000345 if (ret)
346 return ret;
347
Ben Skeggs370c00f2012-08-14 14:11:49 +1000348 nv_parent(dmac)->object_attach = nv50_disp_dmac_object_attach;
349 nv_parent(dmac)->object_detach = nv50_disp_dmac_object_detach;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000350 return 0;
351}
352
Ben Skeggs70cabe42012-08-14 10:04:04 +1000353struct nouveau_ofuncs
Ben Skeggs370c00f2012-08-14 14:11:49 +1000354nv50_disp_sync_ofuncs = {
355 .ctor = nv50_disp_sync_ctor,
Ben Skeggs70cabe42012-08-14 10:04:04 +1000356 .dtor = nv50_disp_dmac_dtor,
357 .init = nv50_disp_dmac_init,
358 .fini = nv50_disp_dmac_fini,
359 .rd32 = nv50_disp_chan_rd32,
360 .wr32 = nv50_disp_chan_wr32,
361};
362
363/*******************************************************************************
Ben Skeggs370c00f2012-08-14 14:11:49 +1000364 * EVO overlay channel objects
Ben Skeggs70cabe42012-08-14 10:04:04 +1000365 ******************************************************************************/
366
367static int
Ben Skeggs370c00f2012-08-14 14:11:49 +1000368nv50_disp_ovly_ctor(struct nouveau_object *parent,
Ben Skeggs70cabe42012-08-14 10:04:04 +1000369 struct nouveau_object *engine,
370 struct nouveau_oclass *oclass, void *data, u32 size,
371 struct nouveau_object **pobject)
372{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000373 struct nv50_display_ovly_class *args = data;
374 struct nv50_disp_dmac *dmac;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000375 int ret;
376
Ben Skeggs370c00f2012-08-14 14:11:49 +1000377 if (size < sizeof(*data) || args->head > 1)
378 return -EINVAL;
379
380 ret = nv50_disp_dmac_create_(parent, engine, oclass, args->pushbuf,
381 3 + args->head, sizeof(*dmac),
382 (void **)&dmac);
383 *pobject = nv_object(dmac);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000384 if (ret)
385 return ret;
386
Ben Skeggs370c00f2012-08-14 14:11:49 +1000387 nv_parent(dmac)->object_attach = nv50_disp_dmac_object_attach;
388 nv_parent(dmac)->object_detach = nv50_disp_dmac_object_detach;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000389 return 0;
390}
391
Ben Skeggs370c00f2012-08-14 14:11:49 +1000392struct nouveau_ofuncs
393nv50_disp_ovly_ofuncs = {
394 .ctor = nv50_disp_ovly_ctor,
395 .dtor = nv50_disp_dmac_dtor,
396 .init = nv50_disp_dmac_init,
397 .fini = nv50_disp_dmac_fini,
398 .rd32 = nv50_disp_chan_rd32,
399 .wr32 = nv50_disp_chan_wr32,
400};
401
402/*******************************************************************************
403 * EVO PIO channel base class
404 ******************************************************************************/
405
406static int
407nv50_disp_pioc_create_(struct nouveau_object *parent,
408 struct nouveau_object *engine,
409 struct nouveau_oclass *oclass, int chid,
410 int length, void **pobject)
411{
412 return nv50_disp_chan_create_(parent, engine, oclass, chid,
413 length, pobject);
414}
415
Ben Skeggs70cabe42012-08-14 10:04:04 +1000416static void
417nv50_disp_pioc_dtor(struct nouveau_object *object)
418{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000419 struct nv50_disp_pioc *pioc = (void *)object;
420 nv50_disp_chan_destroy(&pioc->base);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000421}
422
423static int
424nv50_disp_pioc_init(struct nouveau_object *object)
425{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000426 struct nv50_disp_priv *priv = (void *)object->engine;
427 struct nv50_disp_pioc *pioc = (void *)object;
428 int chid = pioc->base.chid;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000429 int ret;
430
Ben Skeggs370c00f2012-08-14 14:11:49 +1000431 ret = nv50_disp_chan_init(&pioc->base);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000432 if (ret)
433 return ret;
434
Ben Skeggs370c00f2012-08-14 14:11:49 +1000435 nv_wr32(priv, 0x610200 + (chid * 0x10), 0x00002000);
436 if (!nv_wait(priv, 0x610200 + (chid * 0x10), 0x00000000, 0x00000000)) {
437 nv_error(pioc, "timeout0: 0x%08x\n",
438 nv_rd32(priv, 0x610200 + (chid * 0x10)));
439 return -EBUSY;
440 }
441
442 nv_wr32(priv, 0x610200 + (chid * 0x10), 0x00000001);
443 if (!nv_wait(priv, 0x610200 + (chid * 0x10), 0x00030000, 0x00010000)) {
444 nv_error(pioc, "timeout1: 0x%08x\n",
445 nv_rd32(priv, 0x610200 + (chid * 0x10)));
446 return -EBUSY;
447 }
448
Ben Skeggs70cabe42012-08-14 10:04:04 +1000449 return 0;
450}
451
452static int
453nv50_disp_pioc_fini(struct nouveau_object *object, bool suspend)
454{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000455 struct nv50_disp_priv *priv = (void *)object->engine;
456 struct nv50_disp_pioc *pioc = (void *)object;
457 int chid = pioc->base.chid;
458
459 nv_mask(priv, 0x610200 + (chid * 0x10), 0x00000001, 0x00000000);
460 if (!nv_wait(priv, 0x610200 + (chid * 0x10), 0x00030000, 0x00000000)) {
461 nv_error(pioc, "timeout: 0x%08x\n",
462 nv_rd32(priv, 0x610200 + (chid * 0x10)));
463 if (suspend)
464 return -EBUSY;
465 }
466
467 return nv50_disp_chan_fini(&pioc->base, suspend);
468}
469
470/*******************************************************************************
471 * EVO immediate overlay channel objects
472 ******************************************************************************/
473
474static int
475nv50_disp_oimm_ctor(struct nouveau_object *parent,
476 struct nouveau_object *engine,
477 struct nouveau_oclass *oclass, void *data, u32 size,
478 struct nouveau_object **pobject)
479{
480 struct nv50_display_oimm_class *args = data;
481 struct nv50_disp_pioc *pioc;
482 int ret;
483
484 if (size < sizeof(*args) || args->head > 1)
485 return -EINVAL;
486
487 ret = nv50_disp_pioc_create_(parent, engine, oclass, 5 + args->head,
488 sizeof(*pioc), (void **)&pioc);
489 *pobject = nv_object(pioc);
490 if (ret)
491 return ret;
492
493 return 0;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000494}
495
496struct nouveau_ofuncs
Ben Skeggs370c00f2012-08-14 14:11:49 +1000497nv50_disp_oimm_ofuncs = {
498 .ctor = nv50_disp_oimm_ctor,
499 .dtor = nv50_disp_pioc_dtor,
500 .init = nv50_disp_pioc_init,
501 .fini = nv50_disp_pioc_fini,
502 .rd32 = nv50_disp_chan_rd32,
503 .wr32 = nv50_disp_chan_wr32,
504};
505
506/*******************************************************************************
507 * EVO cursor channel objects
508 ******************************************************************************/
509
510static int
511nv50_disp_curs_ctor(struct nouveau_object *parent,
512 struct nouveau_object *engine,
513 struct nouveau_oclass *oclass, void *data, u32 size,
514 struct nouveau_object **pobject)
515{
516 struct nv50_display_curs_class *args = data;
517 struct nv50_disp_pioc *pioc;
518 int ret;
519
520 if (size < sizeof(*args) || args->head > 1)
521 return -EINVAL;
522
523 ret = nv50_disp_pioc_create_(parent, engine, oclass, 7 + args->head,
524 sizeof(*pioc), (void **)&pioc);
525 *pobject = nv_object(pioc);
526 if (ret)
527 return ret;
528
529 return 0;
530}
531
532struct nouveau_ofuncs
533nv50_disp_curs_ofuncs = {
534 .ctor = nv50_disp_curs_ctor,
Ben Skeggs70cabe42012-08-14 10:04:04 +1000535 .dtor = nv50_disp_pioc_dtor,
536 .init = nv50_disp_pioc_init,
537 .fini = nv50_disp_pioc_fini,
538 .rd32 = nv50_disp_chan_rd32,
539 .wr32 = nv50_disp_chan_wr32,
540};
541
542/*******************************************************************************
543 * Base display object
544 ******************************************************************************/
545
546static int
547nv50_disp_base_ctor(struct nouveau_object *parent,
548 struct nouveau_object *engine,
549 struct nouveau_oclass *oclass, void *data, u32 size,
550 struct nouveau_object **pobject)
551{
552 struct nv50_disp_priv *priv = (void *)engine;
553 struct nv50_disp_base *base;
554 int ret;
555
556 ret = nouveau_parent_create(parent, engine, oclass, 0,
557 priv->sclass, 0, &base);
558 *pobject = nv_object(base);
559 if (ret)
560 return ret;
561
Ben Skeggs370c00f2012-08-14 14:11:49 +1000562 return nouveau_ramht_new(parent, parent, 0x1000, 0, &base->ramht);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000563}
564
565static void
566nv50_disp_base_dtor(struct nouveau_object *object)
567{
568 struct nv50_disp_base *base = (void *)object;
Ben Skeggs370c00f2012-08-14 14:11:49 +1000569 nouveau_ramht_ref(NULL, &base->ramht);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000570 nouveau_parent_destroy(&base->base);
571}
572
573static int
574nv50_disp_base_init(struct nouveau_object *object)
575{
Ben Skeggsab772142012-08-14 11:29:57 +1000576 struct nv50_disp_priv *priv = (void *)object->engine;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000577 struct nv50_disp_base *base = (void *)object;
Ben Skeggsab772142012-08-14 11:29:57 +1000578 int ret, i;
579 u32 tmp;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000580
581 ret = nouveau_parent_init(&base->base);
582 if (ret)
583 return ret;
584
Ben Skeggsab772142012-08-14 11:29:57 +1000585 /* The below segments of code copying values from one register to
586 * another appear to inform EVO of the display capabilities or
587 * something similar. NFI what the 0x614004 caps are for..
588 */
589 tmp = nv_rd32(priv, 0x614004);
590 nv_wr32(priv, 0x610184, tmp);
591
592 /* ... CRTC caps */
593 for (i = 0; i < priv->head.nr; i++) {
594 tmp = nv_rd32(priv, 0x616100 + (i * 0x800));
595 nv_wr32(priv, 0x610190 + (i * 0x10), tmp);
596 tmp = nv_rd32(priv, 0x616104 + (i * 0x800));
597 nv_wr32(priv, 0x610194 + (i * 0x10), tmp);
598 tmp = nv_rd32(priv, 0x616108 + (i * 0x800));
599 nv_wr32(priv, 0x610198 + (i * 0x10), tmp);
600 tmp = nv_rd32(priv, 0x61610c + (i * 0x800));
601 nv_wr32(priv, 0x61019c + (i * 0x10), tmp);
602 }
603
604 /* ... DAC caps */
605 for (i = 0; i < priv->dac.nr; i++) {
606 tmp = nv_rd32(priv, 0x61a000 + (i * 0x800));
607 nv_wr32(priv, 0x6101d0 + (i * 0x04), tmp);
608 }
609
610 /* ... SOR caps */
611 for (i = 0; i < priv->sor.nr; i++) {
612 tmp = nv_rd32(priv, 0x61c000 + (i * 0x800));
613 nv_wr32(priv, 0x6101e0 + (i * 0x04), tmp);
614 }
615
616 /* ... EXT caps */
617 for (i = 0; i < 3; i++) {
618 tmp = nv_rd32(priv, 0x61e000 + (i * 0x800));
619 nv_wr32(priv, 0x6101f0 + (i * 0x04), tmp);
620 }
621
Ben Skeggs446b05a2012-08-14 12:50:14 +1000622 /* steal display away from vbios, or something like that */
623 if (nv_rd32(priv, 0x610024) & 0x00000100) {
624 nv_wr32(priv, 0x610024, 0x00000100);
625 nv_mask(priv, 0x6194e8, 0x00000001, 0x00000000);
626 if (!nv_wait(priv, 0x6194e8, 0x00000002, 0x00000000)) {
627 nv_error(priv, "timeout acquiring display\n");
628 return -EBUSY;
629 }
630 }
631
632 /* point at display engine memory area (hash table, objects) */
Ben Skeggs370c00f2012-08-14 14:11:49 +1000633 nv_wr32(priv, 0x610010, (nv_gpuobj(base->ramht)->addr >> 8) | 9);
Ben Skeggs446b05a2012-08-14 12:50:14 +1000634
635 /* enable supervisor interrupts, disable everything else */
Ben Skeggs370c00f2012-08-14 14:11:49 +1000636 nv_wr32(priv, 0x61002c, 0x00000370);
637 nv_wr32(priv, 0x610028, 0x00000000);
Ben Skeggs70cabe42012-08-14 10:04:04 +1000638 return 0;
639}
640
641static int
642nv50_disp_base_fini(struct nouveau_object *object, bool suspend)
643{
Ben Skeggs446b05a2012-08-14 12:50:14 +1000644 struct nv50_disp_priv *priv = (void *)object->engine;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000645 struct nv50_disp_base *base = (void *)object;
Ben Skeggs446b05a2012-08-14 12:50:14 +1000646
647 /* disable all interrupts */
648 nv_wr32(priv, 0x610024, 0x00000000);
649 nv_wr32(priv, 0x610020, 0x00000000);
650
Ben Skeggs70cabe42012-08-14 10:04:04 +1000651 return nouveau_parent_fini(&base->base, suspend);
652}
653
654struct nouveau_ofuncs
655nv50_disp_base_ofuncs = {
656 .ctor = nv50_disp_base_ctor,
657 .dtor = nv50_disp_base_dtor,
658 .init = nv50_disp_base_init,
659 .fini = nv50_disp_base_fini,
660};
661
Ben Skeggsef22c8b2012-11-09 09:32:56 +1000662static struct nouveau_omthds
663nv50_disp_base_omthds[] = {
664 { SOR_MTHD(NV50_DISP_SOR_PWR) , nv50_sor_mthd },
Ben Skeggs4a230fa2012-11-09 11:25:37 +1000665 { SOR_MTHD(NV50_DISP_SOR_LVDS_SCRIPT) , nv50_sor_mthd },
Ben Skeggsef22c8b2012-11-09 09:32:56 +1000666 { DAC_MTHD(NV50_DISP_DAC_PWR) , nv50_dac_mthd },
667 { DAC_MTHD(NV50_DISP_DAC_LOAD) , nv50_dac_mthd },
668 {},
669};
670
Ben Skeggs70cabe42012-08-14 10:04:04 +1000671static struct nouveau_oclass
672nv50_disp_base_oclass[] = {
Ben Skeggsef22c8b2012-11-09 09:32:56 +1000673 { NV50_DISP_CLASS, &nv50_disp_base_ofuncs, nv50_disp_base_omthds },
Ben Skeggs370c00f2012-08-14 14:11:49 +1000674 {}
Ben Skeggsebb945a2012-07-20 08:17:34 +1000675};
676
677static struct nouveau_oclass
678nv50_disp_sclass[] = {
Ben Skeggs370c00f2012-08-14 14:11:49 +1000679 { NV50_DISP_MAST_CLASS, &nv50_disp_mast_ofuncs },
680 { NV50_DISP_SYNC_CLASS, &nv50_disp_sync_ofuncs },
681 { NV50_DISP_OVLY_CLASS, &nv50_disp_ovly_ofuncs },
682 { NV50_DISP_OIMM_CLASS, &nv50_disp_oimm_ofuncs },
683 { NV50_DISP_CURS_CLASS, &nv50_disp_curs_ofuncs },
Ben Skeggs70cabe42012-08-14 10:04:04 +1000684 {}
Ben Skeggsebb945a2012-07-20 08:17:34 +1000685};
686
Ben Skeggs70cabe42012-08-14 10:04:04 +1000687/*******************************************************************************
688 * Display context, tracks instmem allocation and prevents more than one
689 * client using the display hardware at any time.
690 ******************************************************************************/
691
692static int
693nv50_disp_data_ctor(struct nouveau_object *parent,
694 struct nouveau_object *engine,
695 struct nouveau_oclass *oclass, void *data, u32 size,
696 struct nouveau_object **pobject)
697{
Ben Skeggs370c00f2012-08-14 14:11:49 +1000698 struct nv50_disp_priv *priv = (void *)engine;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000699 struct nouveau_engctx *ectx;
Ben Skeggs370c00f2012-08-14 14:11:49 +1000700 int ret = -EBUSY;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000701
Ben Skeggs370c00f2012-08-14 14:11:49 +1000702 /* no context needed for channel objects... */
703 if (nv_mclass(parent) != NV_DEVICE_CLASS) {
704 atomic_inc(&parent->refcount);
705 *pobject = parent;
706 return 0;
707 }
Ben Skeggs70cabe42012-08-14 10:04:04 +1000708
Ben Skeggs370c00f2012-08-14 14:11:49 +1000709 /* allocate display hardware to client */
710 mutex_lock(&nv_subdev(priv)->mutex);
711 if (list_empty(&nv_engine(priv)->contexts)) {
712 ret = nouveau_engctx_create(parent, engine, oclass, NULL,
713 0x10000, 0x10000,
714 NVOBJ_FLAG_HEAP, &ectx);
715 *pobject = nv_object(ectx);
716 }
717 mutex_unlock(&nv_subdev(priv)->mutex);
718 return ret;
Ben Skeggs70cabe42012-08-14 10:04:04 +1000719}
720
721struct nouveau_oclass
722nv50_disp_cclass = {
723 .handle = NV_ENGCTX(DISP, 0x50),
724 .ofuncs = &(struct nouveau_ofuncs) {
725 .ctor = nv50_disp_data_ctor,
726 .dtor = _nouveau_engctx_dtor,
727 .init = _nouveau_engctx_init,
728 .fini = _nouveau_engctx_fini,
729 .rd32 = _nouveau_engctx_rd32,
730 .wr32 = _nouveau_engctx_wr32,
731 },
732};
733
734/*******************************************************************************
735 * Display engine implementation
736 ******************************************************************************/
737
Ben Skeggsebb945a2012-07-20 08:17:34 +1000738static void
Ben Skeggs186ecad2012-11-09 12:09:48 +1000739nv50_disp_intr_error(struct nv50_disp_priv *priv)
740{
741 u32 channels = (nv_rd32(priv, 0x610020) & 0x001f0000) >> 16;
742 u32 addr, data;
743 int chid;
744
745 for (chid = 0; chid < 5; chid++) {
746 if (!(channels & (1 << chid)))
747 continue;
748
749 nv_wr32(priv, 0x610020, 0x00010000 << chid);
750 addr = nv_rd32(priv, 0x610080 + (chid * 0x08));
751 data = nv_rd32(priv, 0x610084 + (chid * 0x08));
752 nv_wr32(priv, 0x610080 + (chid * 0x08), 0x90000000);
753
754 nv_error(priv, "chid %d mthd 0x%04x data 0x%08x 0x%08x\n",
755 chid, addr & 0xffc, data, addr);
756 }
757}
758
759static void
Ben Skeggsebb945a2012-07-20 08:17:34 +1000760nv50_disp_intr_vblank(struct nv50_disp_priv *priv, int crtc)
761{
762 struct nouveau_disp *disp = &priv->base;
763 struct nouveau_software_chan *chan, *temp;
764 unsigned long flags;
765
766 spin_lock_irqsave(&disp->vblank.lock, flags);
767 list_for_each_entry_safe(chan, temp, &disp->vblank.list, vblank.head) {
768 if (chan->vblank.crtc != crtc)
769 continue;
770
771 nv_wr32(priv, 0x001704, chan->vblank.channel);
772 nv_wr32(priv, 0x001710, 0x80000000 | chan->vblank.ctxdma);
773
774 if (nv_device(priv)->chipset == 0x50) {
775 nv_wr32(priv, 0x001570, chan->vblank.offset);
776 nv_wr32(priv, 0x001574, chan->vblank.value);
777 } else {
778 if (nv_device(priv)->chipset >= 0xc0) {
779 nv_wr32(priv, 0x06000c,
780 upper_32_bits(chan->vblank.offset));
781 }
782 nv_wr32(priv, 0x060010, chan->vblank.offset);
783 nv_wr32(priv, 0x060014, chan->vblank.value);
784 }
785
786 list_del(&chan->vblank.head);
787 if (disp->vblank.put)
788 disp->vblank.put(disp->vblank.data, crtc);
789 }
790 spin_unlock_irqrestore(&disp->vblank.lock, flags);
791
792 if (disp->vblank.notify)
793 disp->vblank.notify(disp->vblank.data, crtc);
794}
795
Ben Skeggs186ecad2012-11-09 12:09:48 +1000796static u16
797exec_lookup(struct nv50_disp_priv *priv, int head, int outp, u32 ctrl,
798 struct dcb_output *dcb, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
799 struct nvbios_outp *info)
800{
801 struct nouveau_bios *bios = nouveau_bios(priv);
802 u16 mask, type, data;
803
804 if (outp < 4) {
805 type = DCB_OUTPUT_ANALOG;
806 mask = 0;
807 } else {
808 outp -= 4;
809 switch (ctrl & 0x00000f00) {
810 case 0x00000000: type = DCB_OUTPUT_LVDS; mask = 1; break;
811 case 0x00000100: type = DCB_OUTPUT_TMDS; mask = 1; break;
812 case 0x00000200: type = DCB_OUTPUT_TMDS; mask = 2; break;
813 case 0x00000500: type = DCB_OUTPUT_TMDS; mask = 3; break;
814 case 0x00000800: type = DCB_OUTPUT_DP; mask = 1; break;
815 case 0x00000900: type = DCB_OUTPUT_DP; mask = 2; break;
816 default:
817 nv_error(priv, "unknown SOR mc 0x%08x\n", ctrl);
818 return 0x0000;
819 }
820 }
821
822 mask = 0x00c0 & (mask << 6);
823 mask |= 0x0001 << outp;
824 mask |= 0x0100 << head;
825
826 data = dcb_outp_match(bios, type, mask, ver, hdr, dcb);
827 if (!data)
828 return 0x0000;
829
830 return nvbios_outp_match(bios, type, mask, ver, hdr, cnt, len, info);
831}
832
833static bool
834exec_script(struct nv50_disp_priv *priv, int head, int id)
835{
836 struct nouveau_bios *bios = nouveau_bios(priv);
837 struct nvbios_outp info;
838 struct dcb_output dcb;
839 u8 ver, hdr, cnt, len;
840 u16 data;
841 u32 ctrl = 0x00000000;
842 int i;
843
844 for (i = 0; !(ctrl & (1 << head)) && i < 3; i++)
845 ctrl = nv_rd32(priv, 0x610b5c + (i * 8));
846
847 if (nv_device(priv)->chipset < 0x90 ||
848 nv_device(priv)->chipset == 0x92 ||
849 nv_device(priv)->chipset == 0xa0) {
850 for (i = 0; !(ctrl & (1 << head)) && i < 2; i++)
851 ctrl = nv_rd32(priv, 0x610b74 + (i * 8));
852 i += 3;
853 } else {
854 for (i = 0; !(ctrl & (1 << head)) && i < 4; i++)
855 ctrl = nv_rd32(priv, 0x610798 + (i * 8));
856 i += 3;
857 }
858
859 if (!(ctrl & (1 << head)))
860 return false;
861
862 data = exec_lookup(priv, head, i, ctrl, &dcb, &ver, &hdr, &cnt, &len, &info);
863 if (data) {
864 struct nvbios_init init = {
865 .subdev = nv_subdev(priv),
866 .bios = bios,
867 .offset = info.script[id],
868 .outp = &dcb,
869 .crtc = head,
870 .execute = 1,
871 };
872
873 return nvbios_exec(&init) == 0;
874 }
875
876 return false;
877}
878
879static u32
880exec_clkcmp(struct nv50_disp_priv *priv, int head, int id, u32 pclk,
881 struct dcb_output *outp)
882{
883 struct nouveau_bios *bios = nouveau_bios(priv);
884 struct nvbios_outp info1;
885 struct nvbios_ocfg info2;
886 u8 ver, hdr, cnt, len;
887 u16 data, conf;
888 u32 ctrl = 0x00000000;
889 int i;
890
891 for (i = 0; !(ctrl & (1 << head)) && i < 3; i++)
892 ctrl = nv_rd32(priv, 0x610b58 + (i * 8));
893
894 if (nv_device(priv)->chipset < 0x90 ||
895 nv_device(priv)->chipset == 0x92 ||
896 nv_device(priv)->chipset == 0xa0) {
897 for (i = 0; !(ctrl & (1 << head)) && i < 2; i++)
898 ctrl = nv_rd32(priv, 0x610b70 + (i * 8));
899 i += 3;
900 } else {
901 for (i = 0; !(ctrl & (1 << head)) && i < 4; i++)
902 ctrl = nv_rd32(priv, 0x610794 + (i * 8));
903 i += 3;
904 }
905
906 if (!(ctrl & (1 << head)))
907 return 0x0000;
908
909 data = exec_lookup(priv, head, i, ctrl, outp, &ver, &hdr, &cnt, &len, &info1);
910 if (!data)
911 return 0x0000;
912
913 switch (outp->type) {
914 case DCB_OUTPUT_TMDS:
915 conf = (ctrl & 0x00000f00) >> 8;
916 if (pclk >= 165000)
917 conf |= 0x0100;
918 break;
919 case DCB_OUTPUT_LVDS:
920 conf = priv->sor.lvdsconf;
921 break;
922 case DCB_OUTPUT_DP:
923 conf = (ctrl & 0x00000f00) >> 8;
924 break;
925 case DCB_OUTPUT_ANALOG:
926 default:
927 conf = 0x00ff;
928 break;
929 }
930
931 data = nvbios_ocfg_match(bios, data, conf, &ver, &hdr, &cnt, &len, &info2);
932 if (data) {
933 data = nvbios_oclk_match(bios, info2.clkcmp[id], pclk);
934 if (data) {
935 struct nvbios_init init = {
936 .subdev = nv_subdev(priv),
937 .bios = bios,
938 .offset = data,
939 .outp = outp,
940 .crtc = head,
941 .execute = 1,
942 };
943
944 if (nvbios_exec(&init))
945 return 0x0000;
946 return conf;
947 }
948 }
949
950 return 0x0000;
951}
952
953static void
954nv50_disp_intr_unk10(struct nv50_disp_priv *priv, u32 super)
955{
956 int head = ffs((super & 0x00000060) >> 5) - 1;
957 if (head >= 0) {
958 head = ffs((super & 0x00000180) >> 7) - 1;
959 if (head >= 0)
960 exec_script(priv, head, 1);
961 }
962
963 nv_wr32(priv, 0x610024, 0x00000010);
964 nv_wr32(priv, 0x610030, 0x80000000);
965}
966
967static void
968nv50_disp_intr_unk20_dp(struct nv50_disp_priv *priv,
969 struct dcb_output *outp, u32 pclk)
970{
971 const int link = !(outp->sorconf.link & 1);
972 const int or = ffs(outp->or) - 1;
973 const u32 soff = ( or * 0x800);
974 const u32 loff = (link * 0x080) + soff;
975 const u32 ctrl = nv_rd32(priv, 0x610794 + (or * 8));
Ben Skeggs186ecad2012-11-09 12:09:48 +1000976 const u32 symbol = 100000;
977 u32 dpctrl = nv_rd32(priv, 0x61c10c + loff) & 0x0000f0000;
978 u32 clksor = nv_rd32(priv, 0x614300 + soff);
979 int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
980 int TU, VTUi, VTUf, VTUa;
981 u64 link_data_rate, link_ratio, unk;
982 u32 best_diff = 64 * symbol;
Ben Skeggsbf2c8862012-11-21 14:49:54 +1000983 u32 link_nr, link_bw, bits, r;
Ben Skeggs186ecad2012-11-09 12:09:48 +1000984
985 /* calculate packed data rate for each lane */
986 if (dpctrl > 0x00030000) link_nr = 4;
987 else if (dpctrl > 0x00010000) link_nr = 2;
988 else link_nr = 1;
989
990 if (clksor & 0x000c0000)
991 link_bw = 270000;
992 else
993 link_bw = 162000;
994
Ben Skeggsbf2c8862012-11-21 14:49:54 +1000995 if ((ctrl & 0xf0000) == 0x60000) bits = 30;
996 else if ((ctrl & 0xf0000) == 0x50000) bits = 24;
997 else bits = 18;
998
Ben Skeggs186ecad2012-11-09 12:09:48 +1000999 link_data_rate = (pclk * bits / 8) / link_nr;
1000
1001 /* calculate ratio of packed data rate to link symbol rate */
1002 link_ratio = link_data_rate * symbol;
1003 r = do_div(link_ratio, link_bw);
1004
1005 for (TU = 64; TU >= 32; TU--) {
1006 /* calculate average number of valid symbols in each TU */
1007 u32 tu_valid = link_ratio * TU;
1008 u32 calc, diff;
1009
1010 /* find a hw representation for the fraction.. */
1011 VTUi = tu_valid / symbol;
1012 calc = VTUi * symbol;
1013 diff = tu_valid - calc;
1014 if (diff) {
1015 if (diff >= (symbol / 2)) {
1016 VTUf = symbol / (symbol - diff);
1017 if (symbol - (VTUf * diff))
1018 VTUf++;
1019
1020 if (VTUf <= 15) {
1021 VTUa = 1;
1022 calc += symbol - (symbol / VTUf);
1023 } else {
1024 VTUa = 0;
1025 VTUf = 1;
1026 calc += symbol;
1027 }
1028 } else {
1029 VTUa = 0;
1030 VTUf = min((int)(symbol / diff), 15);
1031 calc += symbol / VTUf;
1032 }
1033
1034 diff = calc - tu_valid;
1035 } else {
1036 /* no remainder, but the hw doesn't like the fractional
1037 * part to be zero. decrement the integer part and
1038 * have the fraction add a whole symbol back
1039 */
1040 VTUa = 0;
1041 VTUf = 1;
1042 VTUi--;
1043 }
1044
1045 if (diff < best_diff) {
1046 best_diff = diff;
1047 bestTU = TU;
1048 bestVTUa = VTUa;
1049 bestVTUf = VTUf;
1050 bestVTUi = VTUi;
1051 if (diff == 0)
1052 break;
1053 }
1054 }
1055
1056 if (!bestTU) {
1057 nv_error(priv, "unable to find suitable dp config\n");
1058 return;
1059 }
1060
1061 /* XXX close to vbios numbers, but not right */
1062 unk = (symbol - link_ratio) * bestTU;
1063 unk *= link_ratio;
1064 r = do_div(unk, symbol);
1065 r = do_div(unk, symbol);
1066 unk += 6;
1067
1068 nv_mask(priv, 0x61c10c + loff, 0x000001fc, bestTU << 2);
1069 nv_mask(priv, 0x61c128 + loff, 0x010f7f3f, bestVTUa << 24 |
1070 bestVTUf << 16 |
1071 bestVTUi << 8 | unk);
1072}
1073
1074static void
1075nv50_disp_intr_unk20(struct nv50_disp_priv *priv, u32 super)
1076{
1077 struct dcb_output outp;
1078 u32 addr, mask, data;
1079 int head;
1080
1081 /* finish detaching encoder? */
1082 head = ffs((super & 0x00000180) >> 7) - 1;
1083 if (head >= 0)
1084 exec_script(priv, head, 2);
1085
1086 /* check whether a vpll change is required */
1087 head = ffs((super & 0x00000600) >> 9) - 1;
1088 if (head >= 0) {
1089 u32 pclk = nv_rd32(priv, 0x610ad0 + (head * 0x540)) & 0x3fffff;
1090 if (pclk) {
1091 struct nouveau_clock *clk = nouveau_clock(priv);
1092 clk->pll_set(clk, PLL_VPLL0 + head, pclk);
1093 }
1094
1095 nv_mask(priv, 0x614200 + head * 0x800, 0x0000000f, 0x00000000);
1096 }
1097
1098 /* (re)attach the relevant OR to the head */
1099 head = ffs((super & 0x00000180) >> 7) - 1;
1100 if (head >= 0) {
1101 u32 pclk = nv_rd32(priv, 0x610ad0 + (head * 0x540)) & 0x3fffff;
1102 u32 conf = exec_clkcmp(priv, head, 0, pclk, &outp);
1103 if (conf) {
1104 if (outp.type == DCB_OUTPUT_ANALOG) {
1105 addr = 0x614280 + (ffs(outp.or) - 1) * 0x800;
1106 mask = 0xffffffff;
1107 data = 0x00000000;
1108 } else {
1109 if (outp.type == DCB_OUTPUT_DP)
1110 nv50_disp_intr_unk20_dp(priv, &outp, pclk);
1111 addr = 0x614300 + (ffs(outp.or) - 1) * 0x800;
1112 mask = 0x00000707;
1113 data = (conf & 0x0100) ? 0x0101 : 0x0000;
1114 }
1115
1116 nv_mask(priv, addr, mask, data);
1117 }
1118 }
1119
1120 nv_wr32(priv, 0x610024, 0x00000020);
1121 nv_wr32(priv, 0x610030, 0x80000000);
1122}
1123
1124/* If programming a TMDS output on a SOR that can also be configured for
1125 * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
1126 *
1127 * It looks like the VBIOS TMDS scripts make an attempt at this, however,
1128 * the VBIOS scripts on at least one board I have only switch it off on
1129 * link 0, causing a blank display if the output has previously been
1130 * programmed for DisplayPort.
1131 */
1132static void
1133nv50_disp_intr_unk40_tmds(struct nv50_disp_priv *priv, struct dcb_output *outp)
1134{
1135 struct nouveau_bios *bios = nouveau_bios(priv);
1136 const int link = !(outp->sorconf.link & 1);
1137 const int or = ffs(outp->or) - 1;
1138 const u32 loff = (or * 0x800) + (link * 0x80);
1139 const u16 mask = (outp->sorconf.link << 6) | outp->or;
1140 u8 ver, hdr;
1141
1142 if (dcb_outp_match(bios, DCB_OUTPUT_DP, mask, &ver, &hdr, outp))
1143 nv_mask(priv, 0x61c10c + loff, 0x00000001, 0x00000000);
1144}
1145
1146static void
1147nv50_disp_intr_unk40(struct nv50_disp_priv *priv, u32 super)
1148{
1149 int head = ffs((super & 0x00000180) >> 7) - 1;
1150 if (head >= 0) {
1151 struct dcb_output outp;
1152 u32 pclk = nv_rd32(priv, 0x610ad0 + (head * 0x540)) & 0x3fffff;
1153 if (pclk && exec_clkcmp(priv, head, 1, pclk, &outp)) {
1154 if (outp.type == DCB_OUTPUT_TMDS)
1155 nv50_disp_intr_unk40_tmds(priv, &outp);
1156 }
1157 }
1158
1159 nv_wr32(priv, 0x610024, 0x00000040);
1160 nv_wr32(priv, 0x610030, 0x80000000);
1161}
1162
1163static void
1164nv50_disp_intr_super(struct nv50_disp_priv *priv, u32 intr1)
1165{
1166 u32 super = nv_rd32(priv, 0x610030);
1167
1168 nv_debug(priv, "supervisor 0x%08x 0x%08x\n", intr1, super);
1169
1170 if (intr1 & 0x00000010)
1171 nv50_disp_intr_unk10(priv, super);
1172 if (intr1 & 0x00000020)
1173 nv50_disp_intr_unk20(priv, super);
1174 if (intr1 & 0x00000040)
1175 nv50_disp_intr_unk40(priv, super);
1176}
1177
Ben Skeggs70cabe42012-08-14 10:04:04 +10001178void
Ben Skeggsebb945a2012-07-20 08:17:34 +10001179nv50_disp_intr(struct nouveau_subdev *subdev)
1180{
1181 struct nv50_disp_priv *priv = (void *)subdev;
Ben Skeggs186ecad2012-11-09 12:09:48 +10001182 u32 intr0 = nv_rd32(priv, 0x610020);
1183 u32 intr1 = nv_rd32(priv, 0x610024);
Ben Skeggsebb945a2012-07-20 08:17:34 +10001184
Ben Skeggs186ecad2012-11-09 12:09:48 +10001185 if (intr0 & 0x001f0000) {
1186 nv50_disp_intr_error(priv);
1187 intr0 &= ~0x001f0000;
1188 }
1189
1190 if (intr1 & 0x00000004) {
Ben Skeggsebb945a2012-07-20 08:17:34 +10001191 nv50_disp_intr_vblank(priv, 0);
1192 nv_wr32(priv, 0x610024, 0x00000004);
Ben Skeggs186ecad2012-11-09 12:09:48 +10001193 intr1 &= ~0x00000004;
Ben Skeggsebb945a2012-07-20 08:17:34 +10001194 }
1195
Ben Skeggs186ecad2012-11-09 12:09:48 +10001196 if (intr1 & 0x00000008) {
Ben Skeggsebb945a2012-07-20 08:17:34 +10001197 nv50_disp_intr_vblank(priv, 1);
1198 nv_wr32(priv, 0x610024, 0x00000008);
Ben Skeggs186ecad2012-11-09 12:09:48 +10001199 intr1 &= ~0x00000008;
Ben Skeggsebb945a2012-07-20 08:17:34 +10001200 }
1201
Ben Skeggs186ecad2012-11-09 12:09:48 +10001202 if (intr1 & 0x00000070) {
1203 nv50_disp_intr_super(priv, intr1);
1204 intr1 &= ~0x00000070;
1205 }
Ben Skeggsebb945a2012-07-20 08:17:34 +10001206}
1207
1208static int
1209nv50_disp_ctor(struct nouveau_object *parent, struct nouveau_object *engine,
Ben Skeggs370c00f2012-08-14 14:11:49 +10001210 struct nouveau_oclass *oclass, void *data, u32 size,
1211 struct nouveau_object **pobject)
Ben Skeggsebb945a2012-07-20 08:17:34 +10001212{
1213 struct nv50_disp_priv *priv;
1214 int ret;
1215
1216 ret = nouveau_disp_create(parent, engine, oclass, "PDISP",
1217 "display", &priv);
1218 *pobject = nv_object(priv);
1219 if (ret)
1220 return ret;
1221
Ben Skeggs70cabe42012-08-14 10:04:04 +10001222 nv_engine(priv)->sclass = nv50_disp_base_oclass;
1223 nv_engine(priv)->cclass = &nv50_disp_cclass;
Ben Skeggsebb945a2012-07-20 08:17:34 +10001224 nv_subdev(priv)->intr = nv50_disp_intr;
Ben Skeggs70cabe42012-08-14 10:04:04 +10001225 priv->sclass = nv50_disp_sclass;
1226 priv->head.nr = 2;
1227 priv->dac.nr = 3;
1228 priv->sor.nr = 2;
Ben Skeggsef22c8b2012-11-09 09:32:56 +10001229 priv->dac.power = nv50_dac_power;
Ben Skeggs7ebb38b2012-11-09 09:38:06 +10001230 priv->dac.sense = nv50_dac_sense;
Ben Skeggsef22c8b2012-11-09 09:32:56 +10001231 priv->sor.power = nv50_sor_power;
Ben Skeggsebb945a2012-07-20 08:17:34 +10001232
1233 INIT_LIST_HEAD(&priv->base.vblank.list);
1234 spin_lock_init(&priv->base.vblank.lock);
1235 return 0;
1236}
1237
1238struct nouveau_oclass
1239nv50_disp_oclass = {
1240 .handle = NV_ENGINE(DISP, 0x50),
1241 .ofuncs = &(struct nouveau_ofuncs) {
1242 .ctor = nv50_disp_ctor,
1243 .dtor = _nouveau_disp_dtor,
1244 .init = _nouveau_disp_init,
1245 .fini = _nouveau_disp_fini,
1246 },
1247};