]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
drm/nouveau/disp/nv50-: implement a common supervisor 1.0
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / nvkm / engine / disp / nv50.c
1 /*
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 #include "nv50.h"
25 #include "head.h"
26 #include "ior.h"
27 #include "rootnv50.h"
28
29 #include <core/client.h>
30 #include <core/enum.h>
31 #include <core/gpuobj.h>
32 #include <subdev/bios.h>
33 #include <subdev/bios/disp.h>
34 #include <subdev/bios/init.h>
35 #include <subdev/bios/pll.h>
36 #include <subdev/devinit.h>
37 #include <subdev/timer.h>
38
39 static const struct nvkm_disp_oclass *
40 nv50_disp_root_(struct nvkm_disp *base)
41 {
42         return nv50_disp(base)->func->root;
43 }
44
45 static void
46 nv50_disp_intr_(struct nvkm_disp *base)
47 {
48         struct nv50_disp *disp = nv50_disp(base);
49         disp->func->intr(disp);
50 }
51
52 static void *
53 nv50_disp_dtor_(struct nvkm_disp *base)
54 {
55         struct nv50_disp *disp = nv50_disp(base);
56         nvkm_event_fini(&disp->uevent);
57         if (disp->wq)
58                 destroy_workqueue(disp->wq);
59         return disp;
60 }
61
62 static const struct nvkm_disp_func
63 nv50_disp_ = {
64         .dtor = nv50_disp_dtor_,
65         .intr = nv50_disp_intr_,
66         .root = nv50_disp_root_,
67 };
68
69 int
70 nv50_disp_new_(const struct nv50_disp_func *func, struct nvkm_device *device,
71                int index, int heads, struct nvkm_disp **pdisp)
72 {
73         struct nv50_disp *disp;
74         int ret, i;
75
76         if (!(disp = kzalloc(sizeof(*disp), GFP_KERNEL)))
77                 return -ENOMEM;
78         disp->func = func;
79         *pdisp = &disp->base;
80
81         ret = nvkm_disp_ctor(&nv50_disp_, device, index, &disp->base);
82         if (ret)
83                 return ret;
84
85         disp->wq = create_singlethread_workqueue("nvkm-disp");
86         if (!disp->wq)
87                 return -ENOMEM;
88         INIT_WORK(&disp->supervisor, func->super);
89
90         for (i = 0; func->head.new && i < heads; i++) {
91                 ret = func->head.new(&disp->base, i);
92                 if (ret)
93                         return ret;
94         }
95
96         for (i = 0; func->dac.new && i < func->dac.nr; i++) {
97                 ret = func->dac.new(&disp->base, i);
98                 if (ret)
99                         return ret;
100         }
101
102         for (i = 0; func->pior.new && i < func->pior.nr; i++) {
103                 ret = func->pior.new(&disp->base, i);
104                 if (ret)
105                         return ret;
106         }
107
108         for (i = 0; func->sor.new && i < func->sor.nr; i++) {
109                 ret = func->sor.new(&disp->base, i);
110                 if (ret)
111                         return ret;
112         }
113
114         return nvkm_event_init(func->uevent, 1, 1 + (heads * 4), &disp->uevent);
115 }
116
117 static u32
118 nv50_disp_super_iedt(struct nvkm_head *head, struct nvkm_outp *outp,
119                      u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
120                      struct nvbios_outp *iedt)
121 {
122         struct nvkm_bios *bios = head->disp->engine.subdev.device->bios;
123         const u8  l = ffs(outp->info.link);
124         const u16 t = outp->info.hasht;
125         const u16 m = (0x0100 << head->id) | (l << 6) | outp->info.or;
126         u32 data = nvbios_outp_match(bios, t, m, ver, hdr, cnt, len, iedt);
127         if (!data)
128                 OUTP_DBG(outp, "missing IEDT for %04x:%04x", t, m);
129         return data;
130 }
131
132 static void
133 nv50_disp_super_ied_off(struct nvkm_head *head, struct nvkm_ior *ior, int id)
134 {
135         struct nvkm_outp *outp = ior->arm.outp;
136         struct nvbios_outp iedt;
137         u8  ver, hdr, cnt, len;
138         u32 data;
139
140         if (!outp) {
141                 IOR_DBG(ior, "nothing attached");
142                 return;
143         }
144
145         data = nv50_disp_super_iedt(head, outp, &ver, &hdr, &cnt, &len, &iedt);
146         if (!data)
147                 return;
148
149         nvbios_init(&head->disp->engine.subdev, iedt.script[id],
150                 init.outp = &outp->info;
151                 init.or   = ior->id;
152                 init.link = ior->arm.link;
153                 init.head = head->id;
154         );
155 }
156
157 static struct nvkm_ior *
158 nv50_disp_super_ior_arm(struct nvkm_head *head)
159 {
160         struct nvkm_ior *ior;
161         list_for_each_entry(ior, &head->disp->ior, head) {
162                 if (ior->arm.head & (1 << head->id)) {
163                         HEAD_DBG(head, "on %s", ior->name);
164                         return ior;
165                 }
166         }
167         HEAD_DBG(head, "nothing attached");
168         return NULL;
169 }
170
171 static struct nvkm_output *
172 exec_lookup(struct nv50_disp *disp, int head, int or, u32 ctrl,
173             u32 *data, u8 *ver, u8 *hdr, u8 *cnt, u8 *len,
174             struct nvbios_outp *info)
175 {
176         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
177         struct nvkm_bios *bios = subdev->device->bios;
178         struct nvkm_output *outp;
179         u16 mask, type;
180
181         if (or < 4) {
182                 type = DCB_OUTPUT_ANALOG;
183                 mask = 0;
184         } else
185         if (or < 8) {
186                 switch (ctrl & 0x00000f00) {
187                 case 0x00000000: type = DCB_OUTPUT_LVDS; mask = 1; break;
188                 case 0x00000100: type = DCB_OUTPUT_TMDS; mask = 1; break;
189                 case 0x00000200: type = DCB_OUTPUT_TMDS; mask = 2; break;
190                 case 0x00000500: type = DCB_OUTPUT_TMDS; mask = 3; break;
191                 case 0x00000800: type = DCB_OUTPUT_DP; mask = 1; break;
192                 case 0x00000900: type = DCB_OUTPUT_DP; mask = 2; break;
193                 default:
194                         nvkm_error(subdev, "unknown SOR mc %08x\n", ctrl);
195                         return NULL;
196                 }
197                 or  -= 4;
198         } else {
199                 or   = or - 8;
200                 type = 0x0010;
201                 mask = 0;
202                 switch (ctrl & 0x00000f00) {
203                 case 0x00000000: type |= disp->pior.type[or]; break;
204                 default:
205                         nvkm_error(subdev, "unknown PIOR mc %08x\n", ctrl);
206                         return NULL;
207                 }
208         }
209
210         mask  = 0x00c0 & (mask << 6);
211         mask |= 0x0001 << or;
212         mask |= 0x0100 << head;
213
214         list_for_each_entry(outp, &disp->base.outp, head) {
215                 if ((outp->info.hasht & 0xff) == type &&
216                     (outp->info.hashm & mask) == mask) {
217                         *data = nvbios_outp_match(bios, outp->info.hasht, mask,
218                                                   ver, hdr, cnt, len, info);
219                         if (!*data)
220                                 return NULL;
221                         return outp;
222                 }
223         }
224
225         return NULL;
226 }
227
228 static struct nvkm_output *
229 exec_script(struct nv50_disp *disp, int head, int id)
230 {
231         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
232         struct nvkm_device *device = subdev->device;
233         struct nvkm_bios *bios = device->bios;
234         struct nvkm_output *outp;
235         struct nvbios_outp info;
236         u8  ver, hdr, cnt, len;
237         u32 data, ctrl = 0;
238         u32 reg;
239         int i;
240
241         /* DAC */
242         for (i = 0; !(ctrl & (1 << head)) && i < disp->func->dac.nr; i++)
243                 ctrl = nvkm_rd32(device, 0x610b5c + (i * 8));
244
245         /* SOR */
246         if (!(ctrl & (1 << head))) {
247                 if (device->chipset  < 0x90 ||
248                     device->chipset == 0x92 ||
249                     device->chipset == 0xa0) {
250                         reg = 0x610b74;
251                 } else {
252                         reg = 0x610798;
253                 }
254                 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->sor.nr; i++)
255                         ctrl = nvkm_rd32(device, reg + (i * 8));
256                 i += 4;
257         }
258
259         /* PIOR */
260         if (!(ctrl & (1 << head))) {
261                 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->pior.nr; i++)
262                         ctrl = nvkm_rd32(device, 0x610b84 + (i * 8));
263                 i += 8;
264         }
265
266         if (!(ctrl & (1 << head)))
267                 return NULL;
268         i--;
269
270         outp = exec_lookup(disp, head, i, ctrl, &data, &ver, &hdr, &cnt, &len, &info);
271         if (outp) {
272                 struct nvbios_init init = {
273                         .subdev = subdev,
274                         .bios = bios,
275                         .offset = info.script[id],
276                         .outp = &outp->info,
277                         .crtc = head,
278                         .execute = 1,
279                 };
280
281                 nvbios_exec(&init);
282         }
283
284         return outp;
285 }
286
287 static struct nvkm_output *
288 exec_clkcmp(struct nv50_disp *disp, int head, int id, u32 pclk, u32 *conf)
289 {
290         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
291         struct nvkm_device *device = subdev->device;
292         struct nvkm_bios *bios = device->bios;
293         struct nvkm_output *outp;
294         struct nvbios_outp info1;
295         struct nvbios_ocfg info2;
296         u8  ver, hdr, cnt, len;
297         u32 data, ctrl = 0;
298         u32 reg;
299         int i;
300
301         /* DAC */
302         for (i = 0; !(ctrl & (1 << head)) && i < disp->func->dac.nr; i++)
303                 ctrl = nvkm_rd32(device, 0x610b58 + (i * 8));
304
305         /* SOR */
306         if (!(ctrl & (1 << head))) {
307                 if (device->chipset  < 0x90 ||
308                     device->chipset == 0x92 ||
309                     device->chipset == 0xa0) {
310                         reg = 0x610b70;
311                 } else {
312                         reg = 0x610794;
313                 }
314                 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->sor.nr; i++)
315                         ctrl = nvkm_rd32(device, reg + (i * 8));
316                 i += 4;
317         }
318
319         /* PIOR */
320         if (!(ctrl & (1 << head))) {
321                 for (i = 0; !(ctrl & (1 << head)) && i < disp->func->pior.nr; i++)
322                         ctrl = nvkm_rd32(device, 0x610b80 + (i * 8));
323                 i += 8;
324         }
325
326         if (!(ctrl & (1 << head)))
327                 return NULL;
328         i--;
329
330         outp = exec_lookup(disp, head, i, ctrl, &data, &ver, &hdr, &cnt, &len, &info1);
331         if (!outp)
332                 return NULL;
333
334         *conf = (ctrl & 0x00000f00) >> 8;
335         if (outp->info.location == 0) {
336                 switch (outp->info.type) {
337                 case DCB_OUTPUT_TMDS:
338                         if (*conf == 5)
339                                 *conf |= 0x0100;
340                         break;
341                 case DCB_OUTPUT_LVDS:
342                         *conf |= disp->sor.lvdsconf;
343                         break;
344                 default:
345                         break;
346                 }
347         } else {
348                 *conf = (ctrl & 0x00000f00) >> 8;
349                 pclk = pclk / 2;
350         }
351
352         data = nvbios_ocfg_match(bios, data, *conf & 0xff, *conf >> 8,
353                                  &ver, &hdr, &cnt, &len, &info2);
354         if (data && id < 0xff) {
355                 data = nvbios_oclk_match(bios, info2.clkcmp[id], pclk);
356                 if (data) {
357                         struct nvbios_init init = {
358                                 .subdev = subdev,
359                                 .bios = bios,
360                                 .offset = data,
361                                 .outp = &outp->info,
362                                 .crtc = head,
363                                 .execute = 1,
364                         };
365
366                         nvbios_exec(&init);
367                 }
368         }
369
370         return outp;
371 }
372
373 static void
374 nv50_disp_intr_unk40_0(struct nv50_disp *disp, int head)
375 {
376         struct nvkm_device *device = disp->base.engine.subdev.device;
377         struct nvkm_output *outp;
378         u32 pclk = nvkm_rd32(device, 0x610ad0 + (head * 0x540)) & 0x3fffff;
379         u32 conf;
380
381         outp = exec_clkcmp(disp, head, 1, pclk, &conf);
382         if (!outp)
383                 return;
384
385         nv50_disp_dptmds_war_3(disp, &outp->info);
386 }
387
388 static void
389 nv50_disp_intr_unk20_2_dp(struct nv50_disp *disp, int head,
390                           struct dcb_output *outp, u32 pclk)
391 {
392         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
393         struct nvkm_device *device = subdev->device;
394         const int link = !(outp->sorconf.link & 1);
395         const int   or = ffs(outp->or) - 1;
396         const u32 soff = (  or * 0x800);
397         const u32 loff = (link * 0x080) + soff;
398         const u32 ctrl = nvkm_rd32(device, 0x610794 + (or * 8));
399         const u32 symbol = 100000;
400         const s32 vactive = nvkm_rd32(device, 0x610af8 + (head * 0x540)) & 0xffff;
401         const s32 vblanke = nvkm_rd32(device, 0x610ae8 + (head * 0x540)) & 0xffff;
402         const s32 vblanks = nvkm_rd32(device, 0x610af0 + (head * 0x540)) & 0xffff;
403         u32 dpctrl = nvkm_rd32(device, 0x61c10c + loff);
404         u32 clksor = nvkm_rd32(device, 0x614300 + soff);
405         int bestTU = 0, bestVTUi = 0, bestVTUf = 0, bestVTUa = 0;
406         int TU, VTUi, VTUf, VTUa;
407         u64 link_data_rate, link_ratio, unk;
408         u32 best_diff = 64 * symbol;
409         u32 link_nr, link_bw, bits;
410         u64 value;
411
412         link_bw = (clksor & 0x000c0000) ? 270000 : 162000;
413         link_nr = hweight32(dpctrl & 0x000f0000);
414
415         /* symbols/hblank - algorithm taken from comments in tegra driver */
416         value = vblanke + vactive - vblanks - 7;
417         value = value * link_bw;
418         do_div(value, pclk);
419         value = value - (3 * !!(dpctrl & 0x00004000)) - (12 / link_nr);
420         nvkm_mask(device, 0x61c1e8 + soff, 0x0000ffff, value);
421
422         /* symbols/vblank - algorithm taken from comments in tegra driver */
423         value = vblanks - vblanke - 25;
424         value = value * link_bw;
425         do_div(value, pclk);
426         value = value - ((36 / link_nr) + 3) - 1;
427         nvkm_mask(device, 0x61c1ec + soff, 0x00ffffff, value);
428
429         /* watermark / activesym */
430         if      ((ctrl & 0xf0000) == 0x60000) bits = 30;
431         else if ((ctrl & 0xf0000) == 0x50000) bits = 24;
432         else                                  bits = 18;
433
434         link_data_rate = (pclk * bits / 8) / link_nr;
435
436         /* calculate ratio of packed data rate to link symbol rate */
437         link_ratio = link_data_rate * symbol;
438         do_div(link_ratio, link_bw);
439
440         for (TU = 64; TU >= 32; TU--) {
441                 /* calculate average number of valid symbols in each TU */
442                 u32 tu_valid = link_ratio * TU;
443                 u32 calc, diff;
444
445                 /* find a hw representation for the fraction.. */
446                 VTUi = tu_valid / symbol;
447                 calc = VTUi * symbol;
448                 diff = tu_valid - calc;
449                 if (diff) {
450                         if (diff >= (symbol / 2)) {
451                                 VTUf = symbol / (symbol - diff);
452                                 if (symbol - (VTUf * diff))
453                                         VTUf++;
454
455                                 if (VTUf <= 15) {
456                                         VTUa  = 1;
457                                         calc += symbol - (symbol / VTUf);
458                                 } else {
459                                         VTUa  = 0;
460                                         VTUf  = 1;
461                                         calc += symbol;
462                                 }
463                         } else {
464                                 VTUa  = 0;
465                                 VTUf  = min((int)(symbol / diff), 15);
466                                 calc += symbol / VTUf;
467                         }
468
469                         diff = calc - tu_valid;
470                 } else {
471                         /* no remainder, but the hw doesn't like the fractional
472                          * part to be zero.  decrement the integer part and
473                          * have the fraction add a whole symbol back
474                          */
475                         VTUa = 0;
476                         VTUf = 1;
477                         VTUi--;
478                 }
479
480                 if (diff < best_diff) {
481                         best_diff = diff;
482                         bestTU = TU;
483                         bestVTUa = VTUa;
484                         bestVTUf = VTUf;
485                         bestVTUi = VTUi;
486                         if (diff == 0)
487                                 break;
488                 }
489         }
490
491         if (!bestTU) {
492                 nvkm_error(subdev, "unable to find suitable dp config\n");
493                 return;
494         }
495
496         /* XXX close to vbios numbers, but not right */
497         unk  = (symbol - link_ratio) * bestTU;
498         unk *= link_ratio;
499         do_div(unk, symbol);
500         do_div(unk, symbol);
501         unk += 6;
502
503         nvkm_mask(device, 0x61c10c + loff, 0x000001fc, bestTU << 2);
504         nvkm_mask(device, 0x61c128 + loff, 0x010f7f3f, bestVTUa << 24 |
505                                                    bestVTUf << 16 |
506                                                    bestVTUi << 8 | unk);
507 }
508
509 static void
510 nv50_disp_intr_unk20_2(struct nv50_disp *disp, int head)
511 {
512         struct nvkm_device *device = disp->base.engine.subdev.device;
513         struct nvkm_output *outp;
514         u32 pclk = nvkm_rd32(device, 0x610ad0 + (head * 0x540)) & 0x3fffff;
515         u32 hval, hreg = 0x614200 + (head * 0x800);
516         u32 oval, oreg;
517         u32 mask, conf;
518
519         outp = exec_clkcmp(disp, head, 0xff, pclk, &conf);
520         if (!outp)
521                 return;
522
523         /* we allow both encoder attach and detach operations to occur
524          * within a single supervisor (ie. modeset) sequence.  the
525          * encoder detach scripts quite often switch off power to the
526          * lanes, which requires the link to be re-trained.
527          *
528          * this is not generally an issue as the sink "must" (heh)
529          * signal an irq when it's lost sync so the driver can
530          * re-train.
531          *
532          * however, on some boards, if one does not configure at least
533          * the gpu side of the link *before* attaching, then various
534          * things can go horribly wrong (PDISP disappearing from mmio,
535          * third supervisor never happens, etc).
536          *
537          * the solution is simply to retrain here, if necessary.  last
538          * i checked, the binary driver userspace does not appear to
539          * trigger this situation (it forces an UPDATE between steps).
540          */
541         if (outp->info.type == DCB_OUTPUT_DP) {
542                 u32 soff = (ffs(outp->info.or) - 1) * 0x08;
543                 u32 ctrl, datarate;
544
545                 if (outp->info.location == 0) {
546                         ctrl = nvkm_rd32(device, 0x610794 + soff);
547                         soff = 1;
548                 } else {
549                         ctrl = nvkm_rd32(device, 0x610b80 + soff);
550                         soff = 2;
551                 }
552
553                 switch ((ctrl & 0x000f0000) >> 16) {
554                 case 6: datarate = pclk * 30; break;
555                 case 5: datarate = pclk * 24; break;
556                 case 2:
557                 default:
558                         datarate = pclk * 18;
559                         break;
560                 }
561
562                 if (nvkm_output_dp_train(outp, datarate / soff))
563                         OUTP_ERR(outp, "link not trained before attach");
564         }
565
566         exec_clkcmp(disp, head, 0, pclk, &conf);
567
568         if (!outp->info.location && outp->info.type == DCB_OUTPUT_ANALOG) {
569                 oreg = 0x614280 + (ffs(outp->info.or) - 1) * 0x800;
570                 oval = 0x00000000;
571                 hval = 0x00000000;
572                 mask = 0xffffffff;
573         } else
574         if (!outp->info.location) {
575                 if (outp->info.type == DCB_OUTPUT_DP)
576                         nv50_disp_intr_unk20_2_dp(disp, head, &outp->info, pclk);
577                 oreg = 0x614300 + (ffs(outp->info.or) - 1) * 0x800;
578                 oval = (conf & 0x0100) ? 0x00000101 : 0x00000000;
579                 hval = 0x00000000;
580                 mask = 0x00000707;
581         } else {
582                 oreg = 0x614380 + (ffs(outp->info.or) - 1) * 0x800;
583                 oval = 0x00000001;
584                 hval = 0x00000001;
585                 mask = 0x00000707;
586         }
587
588         nvkm_mask(device, hreg, 0x0000000f, hval);
589         nvkm_mask(device, oreg, mask, oval);
590
591         nv50_disp_dptmds_war_2(disp, &outp->info);
592 }
593
594 static void
595 nv50_disp_intr_unk20_1(struct nv50_disp *disp, int head)
596 {
597         struct nvkm_device *device = disp->base.engine.subdev.device;
598         struct nvkm_devinit *devinit = device->devinit;
599         u32 pclk = nvkm_rd32(device, 0x610ad0 + (head * 0x540)) & 0x3fffff;
600         if (pclk)
601                 nvkm_devinit_pll_set(devinit, PLL_VPLL0 + head, pclk);
602 }
603
604 static void
605 nv50_disp_intr_unk20_0(struct nv50_disp *disp, int head)
606 {
607         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
608         struct nvkm_output *outp = exec_script(disp, head, 2);
609
610         /* the binary driver does this outside of the supervisor handling
611          * (after the third supervisor from a detach).  we (currently?)
612          * allow both detach/attach to happen in the same set of
613          * supervisor interrupts, so it would make sense to execute this
614          * (full power down?) script after all the detach phases of the
615          * supervisor handling.  like with training if needed from the
616          * second supervisor, nvidia doesn't do this, so who knows if it's
617          * entirely safe, but it does appear to work..
618          *
619          * without this script being run, on some configurations i've
620          * seen, switching from DP to TMDS on a DP connector may result
621          * in a blank screen (SOR_PWR off/on can restore it)
622          */
623         if (outp && outp->info.type == DCB_OUTPUT_DP) {
624                 struct nvkm_output_dp *outpdp = nvkm_output_dp(outp);
625                 struct nvbios_init init = {
626                         .subdev = subdev,
627                         .bios = subdev->device->bios,
628                         .outp = &outp->info,
629                         .crtc = head,
630                         .offset = outpdp->info.script[4],
631                         .execute = 1,
632                 };
633
634                 atomic_set(&outpdp->lt.done, 0);
635                 nvbios_exec(&init);
636         }
637 }
638
639 void
640 nv50_disp_super_1_0(struct nv50_disp *disp, struct nvkm_head *head)
641 {
642         struct nvkm_ior *ior;
643
644         /* Determine which OR, if any, we're detaching from the head. */
645         HEAD_DBG(head, "supervisor 1.0");
646         ior = nv50_disp_super_ior_arm(head);
647         if (!ior)
648                 return;
649
650         /* Execute OffInt1 IED script. */
651         nv50_disp_super_ied_off(head, ior, 1);
652 }
653
654 void
655 nv50_disp_super_1(struct nv50_disp *disp)
656 {
657         struct nvkm_head *head;
658         struct nvkm_ior *ior;
659
660         list_for_each_entry(head, &disp->base.head, head) {
661                 head->func->state(head, &head->arm);
662                 head->func->state(head, &head->asy);
663         }
664
665         list_for_each_entry(ior, &disp->base.ior, head) {
666                 ior->func->state(ior, &ior->arm);
667                 ior->func->state(ior, &ior->asy);
668         }
669 }
670
671 void
672 nv50_disp_super(struct work_struct *work)
673 {
674         struct nv50_disp *disp =
675                 container_of(work, struct nv50_disp, supervisor);
676         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
677         struct nvkm_device *device = subdev->device;
678         struct nvkm_head *head;
679         u32 super = nvkm_rd32(device, 0x610030);
680
681         nvkm_debug(subdev, "supervisor %08x %08x\n", disp->super, super);
682
683         if (disp->super & 0x00000010) {
684                 nv50_disp_chan_mthd(disp->chan[0], NV_DBG_DEBUG);
685                 nv50_disp_super_1(disp);
686                 list_for_each_entry(head, &disp->base.head, head) {
687                         if (!(super & (0x00000020 << head->id)))
688                                 continue;
689                         if (!(super & (0x00000080 << head->id)))
690                                 continue;
691                         nv50_disp_super_1_0(disp, head);
692                 }
693         } else
694         if (disp->super & 0x00000020) {
695                 list_for_each_entry(head, &disp->base.head, head) {
696                         if (!(super & (0x00000080 << head->id)))
697                                 continue;
698                         nv50_disp_intr_unk20_0(disp, head->id);
699                 }
700                 nvkm_outp_route(&disp->base);
701                 list_for_each_entry(head, &disp->base.head, head) {
702                         if (!(super & (0x00000200 << head->id)))
703                                 continue;
704                         nv50_disp_intr_unk20_1(disp, head->id);
705                 }
706                 list_for_each_entry(head, &disp->base.head, head) {
707                         if (!(super & (0x00000080 << head->id)))
708                                 continue;
709                         nv50_disp_intr_unk20_2(disp, head->id);
710                 }
711         } else
712         if (disp->super & 0x00000040) {
713                 list_for_each_entry(head, &disp->base.head, head) {
714                         if (!(super & (0x00000080 << head->id)))
715                                 continue;
716                         nv50_disp_intr_unk40_0(disp, head->id);
717                 }
718                 nv50_disp_update_sppll1(disp);
719         }
720
721         nvkm_wr32(device, 0x610030, 0x80000000);
722 }
723
724 static const struct nvkm_enum
725 nv50_disp_intr_error_type[] = {
726         { 3, "ILLEGAL_MTHD" },
727         { 4, "INVALID_VALUE" },
728         { 5, "INVALID_STATE" },
729         { 7, "INVALID_HANDLE" },
730         {}
731 };
732
733 static const struct nvkm_enum
734 nv50_disp_intr_error_code[] = {
735         { 0x00, "" },
736         {}
737 };
738
739 static void
740 nv50_disp_intr_error(struct nv50_disp *disp, int chid)
741 {
742         struct nvkm_subdev *subdev = &disp->base.engine.subdev;
743         struct nvkm_device *device = subdev->device;
744         u32 data = nvkm_rd32(device, 0x610084 + (chid * 0x08));
745         u32 addr = nvkm_rd32(device, 0x610080 + (chid * 0x08));
746         u32 code = (addr & 0x00ff0000) >> 16;
747         u32 type = (addr & 0x00007000) >> 12;
748         u32 mthd = (addr & 0x00000ffc);
749         const struct nvkm_enum *ec, *et;
750
751         et = nvkm_enum_find(nv50_disp_intr_error_type, type);
752         ec = nvkm_enum_find(nv50_disp_intr_error_code, code);
753
754         nvkm_error(subdev,
755                    "ERROR %d [%s] %02x [%s] chid %d mthd %04x data %08x\n",
756                    type, et ? et->name : "", code, ec ? ec->name : "",
757                    chid, mthd, data);
758
759         if (chid < ARRAY_SIZE(disp->chan)) {
760                 switch (mthd) {
761                 case 0x0080:
762                         nv50_disp_chan_mthd(disp->chan[chid], NV_DBG_ERROR);
763                         break;
764                 default:
765                         break;
766                 }
767         }
768
769         nvkm_wr32(device, 0x610020, 0x00010000 << chid);
770         nvkm_wr32(device, 0x610080 + (chid * 0x08), 0x90000000);
771 }
772
773 void
774 nv50_disp_intr(struct nv50_disp *disp)
775 {
776         struct nvkm_device *device = disp->base.engine.subdev.device;
777         u32 intr0 = nvkm_rd32(device, 0x610020);
778         u32 intr1 = nvkm_rd32(device, 0x610024);
779
780         while (intr0 & 0x001f0000) {
781                 u32 chid = __ffs(intr0 & 0x001f0000) - 16;
782                 nv50_disp_intr_error(disp, chid);
783                 intr0 &= ~(0x00010000 << chid);
784         }
785
786         while (intr0 & 0x0000001f) {
787                 u32 chid = __ffs(intr0 & 0x0000001f);
788                 nv50_disp_chan_uevent_send(disp, chid);
789                 intr0 &= ~(0x00000001 << chid);
790         }
791
792         if (intr1 & 0x00000004) {
793                 nvkm_disp_vblank(&disp->base, 0);
794                 nvkm_wr32(device, 0x610024, 0x00000004);
795         }
796
797         if (intr1 & 0x00000008) {
798                 nvkm_disp_vblank(&disp->base, 1);
799                 nvkm_wr32(device, 0x610024, 0x00000008);
800         }
801
802         if (intr1 & 0x00000070) {
803                 disp->super = (intr1 & 0x00000070);
804                 queue_work(disp->wq, &disp->supervisor);
805                 nvkm_wr32(device, 0x610024, disp->super);
806         }
807 }
808
809 static const struct nv50_disp_func
810 nv50_disp = {
811         .intr = nv50_disp_intr,
812         .uevent = &nv50_disp_chan_uevent,
813         .super = nv50_disp_super,
814         .root = &nv50_disp_root_oclass,
815         .head.new = nv50_head_new,
816         .dac = { .nr = 3, .new = nv50_dac_new },
817         .sor = { .nr = 2, .new = nv50_sor_new },
818         .pior = { .nr = 3, .new = nv50_pior_new },
819 };
820
821 int
822 nv50_disp_new(struct nvkm_device *device, int index, struct nvkm_disp **pdisp)
823 {
824         return nv50_disp_new_(&nv50_disp, device, index, 2, pdisp);
825 }