2 * Copyright (C) 2008 Maarten Maathuis.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
28 #include "nv50_display.h"
29 #include "nouveau_crtc.h"
30 #include "nouveau_encoder.h"
31 #include "nouveau_connector.h"
32 #include "nouveau_fb.h"
33 #include "nouveau_fbcon.h"
34 #include "nouveau_ramht.h"
35 #include "drm_crtc_helper.h"
37 static void nv50_display_isr(struct drm_device
*);
38 static void nv50_display_bh(unsigned long);
41 nv50_sor_nr(struct drm_device
*dev
)
43 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
45 if (dev_priv
->chipset
< 0x90 ||
46 dev_priv
->chipset
== 0x92 ||
47 dev_priv
->chipset
== 0xa0)
54 evo_icmd(struct drm_device
*dev
, int ch
, u32 mthd
, u32 data
)
57 nv_mask(dev
, 0x610300 + (ch
* 0x08), 0x00000001, 0x00000001);
58 nv_wr32(dev
, 0x610304 + (ch
* 0x08), data
);
59 nv_wr32(dev
, 0x610300 + (ch
* 0x08), 0x80000001 | mthd
);
60 if (!nv_wait(dev
, 0x610300 + (ch
* 0x08), 0x80000000, 0x00000000))
62 if (ret
|| (nouveau_reg_debug
& NOUVEAU_REG_DEBUG_EVO
))
63 NV_INFO(dev
, "EvoPIO: %d 0x%04x 0x%08x\n", ch
, mthd
, data
);
64 nv_mask(dev
, 0x610300 + (ch
* 0x08), 0x00000001, 0x00000000);
69 nv50_display_early_init(struct drm_device
*dev
)
71 u32 ctrl
= nv_rd32(dev
, 0x610200);
74 /* check if master evo channel is already active, a good a sign as any
75 * that the display engine is in a weird state (hibernate/kexec), if
76 * it is, do our best to reset the display engine...
78 if ((ctrl
& 0x00000003) == 0x00000003) {
79 NV_INFO(dev
, "PDISP: EVO(0) 0x%08x, resetting...\n", ctrl
);
81 /* deactivate both heads first, PDISP will disappear forever
82 * (well, until you power cycle) on some boards as soon as
83 * PMC_ENABLE is hit unless they are..
85 for (i
= 0; i
< 2; i
++) {
86 evo_icmd(dev
, 0, 0x0880 + (i
* 0x400), 0x05000000);
87 evo_icmd(dev
, 0, 0x089c + (i
* 0x400), 0);
88 evo_icmd(dev
, 0, 0x0840 + (i
* 0x400), 0);
89 evo_icmd(dev
, 0, 0x0844 + (i
* 0x400), 0);
90 evo_icmd(dev
, 0, 0x085c + (i
* 0x400), 0);
91 evo_icmd(dev
, 0, 0x0874 + (i
* 0x400), 0);
93 evo_icmd(dev
, 0, 0x0080, 0);
96 nv_mask(dev
, 0x000200, 0x40000000, 0x00000000);
97 nv_mask(dev
, 0x000200, 0x40000000, 0x40000000);
104 nv50_display_late_takedown(struct drm_device
*dev
)
109 nv50_display_sync(struct drm_device
*dev
)
111 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
112 struct nouveau_timer_engine
*ptimer
= &dev_priv
->engine
.timer
;
113 struct nv50_display
*disp
= nv50_display(dev
);
114 struct nouveau_channel
*evo
= disp
->master
;
118 ret
= RING_SPACE(evo
, 6);
120 BEGIN_RING(evo
, 0, 0x0084, 1);
121 OUT_RING (evo
, 0x80000000);
122 BEGIN_RING(evo
, 0, 0x0080, 1);
124 BEGIN_RING(evo
, 0, 0x0084, 1);
125 OUT_RING (evo
, 0x00000000);
127 nv_wo32(disp
->ntfy
, 0x000, 0x00000000);
130 start
= ptimer
->read(dev
);
132 if (nv_ro32(disp
->ntfy
, 0x000))
134 } while (ptimer
->read(dev
) - start
< 2000000000ULL);
141 nv50_display_init(struct drm_device
*dev
)
143 struct nouveau_channel
*evo
;
147 NV_DEBUG_KMS(dev
, "\n");
149 nv_wr32(dev
, 0x00610184, nv_rd32(dev
, 0x00614004));
152 * I think the 0x006101XX range is some kind of main control area
153 * that enables things.
156 for (i
= 0; i
< 2; i
++) {
157 val
= nv_rd32(dev
, 0x00616100 + (i
* 0x800));
158 nv_wr32(dev
, 0x00610190 + (i
* 0x10), val
);
159 val
= nv_rd32(dev
, 0x00616104 + (i
* 0x800));
160 nv_wr32(dev
, 0x00610194 + (i
* 0x10), val
);
161 val
= nv_rd32(dev
, 0x00616108 + (i
* 0x800));
162 nv_wr32(dev
, 0x00610198 + (i
* 0x10), val
);
163 val
= nv_rd32(dev
, 0x0061610c + (i
* 0x800));
164 nv_wr32(dev
, 0x0061019c + (i
* 0x10), val
);
168 for (i
= 0; i
< 3; i
++) {
169 val
= nv_rd32(dev
, 0x0061a000 + (i
* 0x800));
170 nv_wr32(dev
, 0x006101d0 + (i
* 0x04), val
);
174 for (i
= 0; i
< nv50_sor_nr(dev
); i
++) {
175 val
= nv_rd32(dev
, 0x0061c000 + (i
* 0x800));
176 nv_wr32(dev
, 0x006101e0 + (i
* 0x04), val
);
180 for (i
= 0; i
< 3; i
++) {
181 val
= nv_rd32(dev
, 0x0061e000 + (i
* 0x800));
182 nv_wr32(dev
, 0x006101f0 + (i
* 0x04), val
);
185 for (i
= 0; i
< 3; i
++) {
186 nv_wr32(dev
, NV50_PDISPLAY_DAC_DPMS_CTRL(i
), 0x00550000 |
187 NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING
);
188 nv_wr32(dev
, NV50_PDISPLAY_DAC_CLK_CTRL1(i
), 0x00000001);
191 /* The precise purpose is unknown, i suspect it has something to do
194 if (nv_rd32(dev
, NV50_PDISPLAY_INTR_1
) & 0x100) {
195 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, 0x100);
196 nv_wr32(dev
, 0x006194e8, nv_rd32(dev
, 0x006194e8) & ~1);
197 if (!nv_wait(dev
, 0x006194e8, 2, 0)) {
198 NV_ERROR(dev
, "timeout: (0x6194e8 & 2) != 0\n");
199 NV_ERROR(dev
, "0x6194e8 = 0x%08x\n",
200 nv_rd32(dev
, 0x6194e8));
205 for (i
= 0; i
< 2; i
++) {
206 nv_wr32(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
), 0x2000);
207 if (!nv_wait(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
),
208 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS
, 0)) {
209 NV_ERROR(dev
, "timeout: CURSOR_CTRL2_STATUS == 0\n");
210 NV_ERROR(dev
, "CURSOR_CTRL2 = 0x%08x\n",
211 nv_rd32(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
)));
215 nv_wr32(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
),
216 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_ON
);
217 if (!nv_wait(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
),
218 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS
,
219 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS_ACTIVE
)) {
220 NV_ERROR(dev
, "timeout: "
221 "CURSOR_CTRL2_STATUS_ACTIVE(%d)\n", i
);
222 NV_ERROR(dev
, "CURSOR_CTRL2(%d) = 0x%08x\n", i
,
223 nv_rd32(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
)));
228 nv_wr32(dev
, NV50_PDISPLAY_PIO_CTRL
, 0x00000000);
229 nv_mask(dev
, NV50_PDISPLAY_INTR_0
, 0x00000000, 0x00000000);
230 nv_wr32(dev
, NV50_PDISPLAY_INTR_EN_0
, 0x00000000);
231 nv_mask(dev
, NV50_PDISPLAY_INTR_1
, 0x00000000, 0x00000000);
232 nv_wr32(dev
, NV50_PDISPLAY_INTR_EN_1
,
233 NV50_PDISPLAY_INTR_EN_1_CLK_UNK10
|
234 NV50_PDISPLAY_INTR_EN_1_CLK_UNK20
|
235 NV50_PDISPLAY_INTR_EN_1_CLK_UNK40
);
237 ret
= nv50_evo_init(dev
);
240 evo
= nv50_display(dev
)->master
;
242 nv_wr32(dev
, NV50_PDISPLAY_OBJECTS
, (evo
->ramin
->vinst
>> 8) | 9);
244 ret
= RING_SPACE(evo
, 3);
247 BEGIN_RING(evo
, 0, NV50_EVO_UNK84
, 2);
248 OUT_RING (evo
, NV50_EVO_UNK84_NOTIFY_DISABLED
);
249 OUT_RING (evo
, NvEvoSync
);
251 return nv50_display_sync(dev
);
255 nv50_display_fini(struct drm_device
*dev
)
257 struct nv50_display
*disp
= nv50_display(dev
);
258 struct nouveau_channel
*evo
= disp
->master
;
259 struct drm_crtc
*drm_crtc
;
262 NV_DEBUG_KMS(dev
, "\n");
264 list_for_each_entry(drm_crtc
, &dev
->mode_config
.crtc_list
, head
) {
265 struct nouveau_crtc
*crtc
= nouveau_crtc(drm_crtc
);
267 nv50_crtc_blank(crtc
, true);
270 ret
= RING_SPACE(evo
, 2);
272 BEGIN_RING(evo
, 0, NV50_EVO_UPDATE
, 1);
277 /* Almost like ack'ing a vblank interrupt, maybe in the spirit of
280 list_for_each_entry(drm_crtc
, &dev
->mode_config
.crtc_list
, head
) {
281 struct nouveau_crtc
*crtc
= nouveau_crtc(drm_crtc
);
282 uint32_t mask
= NV50_PDISPLAY_INTR_1_VBLANK_CRTC_(crtc
->index
);
284 if (!crtc
->base
.enabled
)
287 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, mask
);
288 if (!nv_wait(dev
, NV50_PDISPLAY_INTR_1
, mask
, mask
)) {
289 NV_ERROR(dev
, "timeout: (0x610024 & 0x%08x) == "
290 "0x%08x\n", mask
, mask
);
291 NV_ERROR(dev
, "0x610024 = 0x%08x\n",
292 nv_rd32(dev
, NV50_PDISPLAY_INTR_1
));
296 for (i
= 0; i
< 2; i
++) {
297 nv_wr32(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
), 0);
298 if (!nv_wait(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
),
299 NV50_PDISPLAY_CURSOR_CURSOR_CTRL2_STATUS
, 0)) {
300 NV_ERROR(dev
, "timeout: CURSOR_CTRL2_STATUS == 0\n");
301 NV_ERROR(dev
, "CURSOR_CTRL2 = 0x%08x\n",
302 nv_rd32(dev
, NV50_PDISPLAY_CURSOR_CURSOR_CTRL2(i
)));
308 for (i
= 0; i
< 3; i
++) {
309 if (!nv_wait(dev
, NV50_PDISPLAY_SOR_DPMS_STATE(i
),
310 NV50_PDISPLAY_SOR_DPMS_STATE_WAIT
, 0)) {
311 NV_ERROR(dev
, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", i
);
312 NV_ERROR(dev
, "SOR_DPMS_STATE(%d) = 0x%08x\n", i
,
313 nv_rd32(dev
, NV50_PDISPLAY_SOR_DPMS_STATE(i
)));
317 /* disable interrupts. */
318 nv_wr32(dev
, NV50_PDISPLAY_INTR_EN_1
, 0x00000000);
322 nv50_display_create(struct drm_device
*dev
)
324 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
325 struct dcb_table
*dcb
= &dev_priv
->vbios
.dcb
;
326 struct drm_connector
*connector
, *ct
;
327 struct nv50_display
*priv
;
330 NV_DEBUG_KMS(dev
, "\n");
332 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
335 dev_priv
->engine
.display
.priv
= priv
;
337 /* Create CRTC objects */
338 for (i
= 0; i
< 2; i
++)
339 nv50_crtc_create(dev
, i
);
341 /* We setup the encoders from the BIOS table */
342 for (i
= 0 ; i
< dcb
->entries
; i
++) {
343 struct dcb_entry
*entry
= &dcb
->entry
[i
];
345 if (entry
->location
!= DCB_LOC_ON_CHIP
) {
346 NV_WARN(dev
, "Off-chip encoder %d/%d unsupported\n",
347 entry
->type
, ffs(entry
->or) - 1);
351 connector
= nouveau_connector_create(dev
, entry
->connector
);
352 if (IS_ERR(connector
))
355 switch (entry
->type
) {
359 nv50_sor_create(connector
, entry
);
362 nv50_dac_create(connector
, entry
);
365 NV_WARN(dev
, "DCB encoder %d unknown\n", entry
->type
);
370 list_for_each_entry_safe(connector
, ct
,
371 &dev
->mode_config
.connector_list
, head
) {
372 if (!connector
->encoder_ids
[0]) {
373 NV_WARN(dev
, "%s has no encoders, removing\n",
374 drm_get_connector_name(connector
));
375 connector
->funcs
->destroy(connector
);
379 tasklet_init(&priv
->tasklet
, nv50_display_bh
, (unsigned long)dev
);
380 nouveau_irq_register(dev
, 26, nv50_display_isr
);
382 ret
= nv50_evo_create(dev
);
384 nv50_display_destroy(dev
);
392 nv50_display_destroy(struct drm_device
*dev
)
394 struct nv50_display
*disp
= nv50_display(dev
);
396 NV_DEBUG_KMS(dev
, "\n");
398 nv50_evo_destroy(dev
);
399 nouveau_irq_unregister(dev
, 26);
404 nv50_display_flip_stop(struct drm_crtc
*crtc
)
406 struct nv50_display
*disp
= nv50_display(crtc
->dev
);
407 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
408 struct nv50_display_crtc
*dispc
= &disp
->crtc
[nv_crtc
->index
];
409 struct nouveau_channel
*evo
= dispc
->sync
;
412 ret
= RING_SPACE(evo
, 8);
418 BEGIN_RING(evo
, 0, 0x0084, 1);
419 OUT_RING (evo
, 0x00000000);
420 BEGIN_RING(evo
, 0, 0x0094, 1);
421 OUT_RING (evo
, 0x00000000);
422 BEGIN_RING(evo
, 0, 0x00c0, 1);
423 OUT_RING (evo
, 0x00000000);
424 BEGIN_RING(evo
, 0, 0x0080, 1);
425 OUT_RING (evo
, 0x00000000);
430 nv50_display_flip_next(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
431 struct nouveau_channel
*chan
)
433 struct drm_nouveau_private
*dev_priv
= crtc
->dev
->dev_private
;
434 struct nouveau_framebuffer
*nv_fb
= nouveau_framebuffer(fb
);
435 struct nv50_display
*disp
= nv50_display(crtc
->dev
);
436 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
437 struct nv50_display_crtc
*dispc
= &disp
->crtc
[nv_crtc
->index
];
438 struct nouveau_channel
*evo
= dispc
->sync
;
441 ret
= RING_SPACE(evo
, chan
? 25 : 27);
445 /* synchronise with the rendering channel, if necessary */
447 ret
= RING_SPACE(chan
, 10);
453 if (dev_priv
->chipset
< 0xc0) {
454 BEGIN_RING(chan
, NvSubSw
, 0x0060, 2);
455 OUT_RING (chan
, NvEvoSema0
+ nv_crtc
->index
);
456 OUT_RING (chan
, dispc
->sem
.offset
);
457 BEGIN_RING(chan
, NvSubSw
, 0x006c, 1);
458 OUT_RING (chan
, 0xf00d0000 | dispc
->sem
.value
);
459 BEGIN_RING(chan
, NvSubSw
, 0x0064, 2);
460 OUT_RING (chan
, dispc
->sem
.offset
^ 0x10);
461 OUT_RING (chan
, 0x74b1e000);
462 BEGIN_RING(chan
, NvSubSw
, 0x0060, 1);
463 if (dev_priv
->chipset
< 0x84)
464 OUT_RING (chan
, NvSema
);
466 OUT_RING (chan
, chan
->vram_handle
);
468 u64 offset
= chan
->dispc_vma
[nv_crtc
->index
].offset
;
469 offset
+= dispc
->sem
.offset
;
470 BEGIN_NVC0(chan
, 2, NvSubM2MF
, 0x0010, 4);
471 OUT_RING (chan
, upper_32_bits(offset
));
472 OUT_RING (chan
, lower_32_bits(offset
));
473 OUT_RING (chan
, 0xf00d0000 | dispc
->sem
.value
);
474 OUT_RING (chan
, 0x1002);
475 BEGIN_NVC0(chan
, 2, NvSubM2MF
, 0x0010, 4);
476 OUT_RING (chan
, upper_32_bits(offset
));
477 OUT_RING (chan
, lower_32_bits(offset
^ 0x10));
478 OUT_RING (chan
, 0x74b1e000);
479 OUT_RING (chan
, 0x1001);
483 nouveau_bo_wr32(dispc
->sem
.bo
, dispc
->sem
.offset
/ 4,
484 0xf00d0000 | dispc
->sem
.value
);
487 /* queue the flip on the crtc's "display sync" channel */
488 BEGIN_RING(evo
, 0, 0x0100, 1);
489 OUT_RING (evo
, 0xfffe0000);
491 BEGIN_RING(evo
, 0, 0x0084, 1);
492 OUT_RING (evo
, 0x00000100);
494 BEGIN_RING(evo
, 0, 0x0084, 1);
495 OUT_RING (evo
, 0x00000010);
496 /* allows gamma somehow, PDISP will bitch at you if
497 * you don't wait for vblank before changing this..
499 BEGIN_RING(evo
, 0, 0x00e0, 1);
500 OUT_RING (evo
, 0x40000000);
502 BEGIN_RING(evo
, 0, 0x0088, 4);
503 OUT_RING (evo
, dispc
->sem
.offset
);
504 OUT_RING (evo
, 0xf00d0000 | dispc
->sem
.value
);
505 OUT_RING (evo
, 0x74b1e000);
506 OUT_RING (evo
, NvEvoSync
);
507 BEGIN_RING(evo
, 0, 0x00a0, 2);
508 OUT_RING (evo
, 0x00000000);
509 OUT_RING (evo
, 0x00000000);
510 BEGIN_RING(evo
, 0, 0x00c0, 1);
511 OUT_RING (evo
, nv_fb
->r_dma
);
512 BEGIN_RING(evo
, 0, 0x0110, 2);
513 OUT_RING (evo
, 0x00000000);
514 OUT_RING (evo
, 0x00000000);
515 BEGIN_RING(evo
, 0, 0x0800, 5);
516 OUT_RING (evo
, nv_fb
->nvbo
->bo
.offset
>> 8);
518 OUT_RING (evo
, (fb
->height
<< 16) | fb
->width
);
519 OUT_RING (evo
, nv_fb
->r_pitch
);
520 OUT_RING (evo
, nv_fb
->r_format
);
521 BEGIN_RING(evo
, 0, 0x0080, 1);
522 OUT_RING (evo
, 0x00000000);
525 dispc
->sem
.offset
^= 0x10;
531 nv50_display_script_select(struct drm_device
*dev
, struct dcb_entry
*dcb
,
534 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
535 struct nouveau_connector
*nv_connector
= NULL
;
536 struct drm_encoder
*encoder
;
537 struct nvbios
*bios
= &dev_priv
->vbios
;
540 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
541 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
543 if (nv_encoder
->dcb
!= dcb
)
546 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
550 or = ffs(dcb
->or) - 1;
553 script
= (mc
>> 8) & 0xf;
554 if (bios
->fp_no_ddc
) {
555 if (bios
->fp
.dual_link
)
557 if (bios
->fp
.if_is_24bit
)
560 /* determine number of lvds links */
561 if (nv_connector
&& nv_connector
->edid
&&
562 nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
) {
563 /* http://www.spwg.org */
564 if (((u8
*)nv_connector
->edid
)[121] == 2)
567 if (pxclk
>= bios
->fp
.duallink_transition_clk
) {
571 /* determine panel depth */
572 if (script
& 0x0100) {
573 if (bios
->fp
.strapless_is_24bit
& 2)
576 if (bios
->fp
.strapless_is_24bit
& 1)
580 if (nv_connector
&& nv_connector
->edid
&&
581 (nv_connector
->edid
->revision
>= 4) &&
582 (nv_connector
->edid
->input
& 0x70) >= 0x20)
586 if (nouveau_uscript_lvds
>= 0) {
587 NV_INFO(dev
, "override script 0x%04x with 0x%04x "
588 "for output LVDS-%d\n", script
,
589 nouveau_uscript_lvds
, or);
590 script
= nouveau_uscript_lvds
;
594 script
= (mc
>> 8) & 0xf;
598 if (nouveau_uscript_tmds
>= 0) {
599 NV_INFO(dev
, "override script 0x%04x with 0x%04x "
600 "for output TMDS-%d\n", script
,
601 nouveau_uscript_tmds
, or);
602 script
= nouveau_uscript_tmds
;
606 script
= (mc
>> 8) & 0xf;
612 NV_ERROR(dev
, "modeset on unsupported output type!\n");
620 nv50_display_vblank_crtc_handler(struct drm_device
*dev
, int crtc
)
622 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
623 struct nouveau_channel
*chan
, *tmp
;
625 list_for_each_entry_safe(chan
, tmp
, &dev_priv
->vbl_waiting
,
627 if (chan
->nvsw
.vblsem_head
!= crtc
)
630 nouveau_bo_wr32(chan
->notifier_bo
, chan
->nvsw
.vblsem_offset
,
631 chan
->nvsw
.vblsem_rval
);
632 list_del(&chan
->nvsw
.vbl_wait
);
633 drm_vblank_put(dev
, crtc
);
636 drm_handle_vblank(dev
, crtc
);
640 nv50_display_vblank_handler(struct drm_device
*dev
, uint32_t intr
)
642 if (intr
& NV50_PDISPLAY_INTR_1_VBLANK_CRTC_0
)
643 nv50_display_vblank_crtc_handler(dev
, 0);
645 if (intr
& NV50_PDISPLAY_INTR_1_VBLANK_CRTC_1
)
646 nv50_display_vblank_crtc_handler(dev
, 1);
648 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, NV50_PDISPLAY_INTR_1_VBLANK_CRTC
);
652 nv50_display_unk10_handler(struct drm_device
*dev
)
654 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
655 struct nv50_display
*disp
= nv50_display(dev
);
656 u32 unk30
= nv_rd32(dev
, 0x610030), mc
;
657 int i
, crtc
, or = 0, type
= OUTPUT_ANY
;
659 NV_DEBUG_KMS(dev
, "0x610030: 0x%08x\n", unk30
);
660 disp
->irq
.dcb
= NULL
;
662 nv_wr32(dev
, 0x619494, nv_rd32(dev
, 0x619494) & ~8);
664 /* Determine which CRTC we're dealing with, only 1 ever will be
665 * signalled at the same time with the current nouveau code.
667 crtc
= ffs((unk30
& 0x00000060) >> 5) - 1;
671 /* Nothing needs to be done for the encoder */
672 crtc
= ffs((unk30
& 0x00000180) >> 7) - 1;
676 /* Find which encoder was connected to the CRTC */
677 for (i
= 0; type
== OUTPUT_ANY
&& i
< 3; i
++) {
678 mc
= nv_rd32(dev
, NV50_PDISPLAY_DAC_MODE_CTRL_C(i
));
679 NV_DEBUG_KMS(dev
, "DAC-%d mc: 0x%08x\n", i
, mc
);
680 if (!(mc
& (1 << crtc
)))
683 switch ((mc
& 0x00000f00) >> 8) {
684 case 0: type
= OUTPUT_ANALOG
; break;
685 case 1: type
= OUTPUT_TV
; break;
687 NV_ERROR(dev
, "invalid mc, DAC-%d: 0x%08x\n", i
, mc
);
694 for (i
= 0; type
== OUTPUT_ANY
&& i
< nv50_sor_nr(dev
); i
++) {
695 if (dev_priv
->chipset
< 0x90 ||
696 dev_priv
->chipset
== 0x92 ||
697 dev_priv
->chipset
== 0xa0)
698 mc
= nv_rd32(dev
, NV50_PDISPLAY_SOR_MODE_CTRL_C(i
));
700 mc
= nv_rd32(dev
, NV90_PDISPLAY_SOR_MODE_CTRL_C(i
));
702 NV_DEBUG_KMS(dev
, "SOR-%d mc: 0x%08x\n", i
, mc
);
703 if (!(mc
& (1 << crtc
)))
706 switch ((mc
& 0x00000f00) >> 8) {
707 case 0: type
= OUTPUT_LVDS
; break;
708 case 1: type
= OUTPUT_TMDS
; break;
709 case 2: type
= OUTPUT_TMDS
; break;
710 case 5: type
= OUTPUT_TMDS
; break;
711 case 8: type
= OUTPUT_DP
; break;
712 case 9: type
= OUTPUT_DP
; break;
714 NV_ERROR(dev
, "invalid mc, SOR-%d: 0x%08x\n", i
, mc
);
721 /* There was no encoder to disable */
722 if (type
== OUTPUT_ANY
)
725 /* Disable the encoder */
726 for (i
= 0; i
< dev_priv
->vbios
.dcb
.entries
; i
++) {
727 struct dcb_entry
*dcb
= &dev_priv
->vbios
.dcb
.entry
[i
];
729 if (dcb
->type
== type
&& (dcb
->or & (1 << or))) {
730 nouveau_bios_run_display_table(dev
, 0, -1, dcb
, -1);
736 NV_ERROR(dev
, "no dcb for %d %d 0x%08x\n", or, type
, mc
);
738 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, NV50_PDISPLAY_INTR_1_CLK_UNK10
);
739 nv_wr32(dev
, 0x610030, 0x80000000);
743 nv50_display_unk20_handler(struct drm_device
*dev
)
745 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
746 struct nv50_display
*disp
= nv50_display(dev
);
747 u32 unk30
= nv_rd32(dev
, 0x610030), tmp
, pclk
, script
, mc
= 0;
748 struct dcb_entry
*dcb
;
749 int i
, crtc
, or = 0, type
= OUTPUT_ANY
;
751 NV_DEBUG_KMS(dev
, "0x610030: 0x%08x\n", unk30
);
754 nouveau_bios_run_display_table(dev
, 0, -2, dcb
, -1);
755 disp
->irq
.dcb
= NULL
;
758 /* CRTC clock change requested? */
759 crtc
= ffs((unk30
& 0x00000600) >> 9) - 1;
761 pclk
= nv_rd32(dev
, NV50_PDISPLAY_CRTC_P(crtc
, CLOCK
));
764 nv50_crtc_set_clock(dev
, crtc
, pclk
);
766 tmp
= nv_rd32(dev
, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc
));
768 nv_wr32(dev
, NV50_PDISPLAY_CRTC_CLK_CTRL2(crtc
), tmp
);
771 /* Nothing needs to be done for the encoder */
772 crtc
= ffs((unk30
& 0x00000180) >> 7) - 1;
775 pclk
= nv_rd32(dev
, NV50_PDISPLAY_CRTC_P(crtc
, CLOCK
)) & 0x003fffff;
777 /* Find which encoder is connected to the CRTC */
778 for (i
= 0; type
== OUTPUT_ANY
&& i
< 3; i
++) {
779 mc
= nv_rd32(dev
, NV50_PDISPLAY_DAC_MODE_CTRL_P(i
));
780 NV_DEBUG_KMS(dev
, "DAC-%d mc: 0x%08x\n", i
, mc
);
781 if (!(mc
& (1 << crtc
)))
784 switch ((mc
& 0x00000f00) >> 8) {
785 case 0: type
= OUTPUT_ANALOG
; break;
786 case 1: type
= OUTPUT_TV
; break;
788 NV_ERROR(dev
, "invalid mc, DAC-%d: 0x%08x\n", i
, mc
);
795 for (i
= 0; type
== OUTPUT_ANY
&& i
< nv50_sor_nr(dev
); i
++) {
796 if (dev_priv
->chipset
< 0x90 ||
797 dev_priv
->chipset
== 0x92 ||
798 dev_priv
->chipset
== 0xa0)
799 mc
= nv_rd32(dev
, NV50_PDISPLAY_SOR_MODE_CTRL_P(i
));
801 mc
= nv_rd32(dev
, NV90_PDISPLAY_SOR_MODE_CTRL_P(i
));
803 NV_DEBUG_KMS(dev
, "SOR-%d mc: 0x%08x\n", i
, mc
);
804 if (!(mc
& (1 << crtc
)))
807 switch ((mc
& 0x00000f00) >> 8) {
808 case 0: type
= OUTPUT_LVDS
; break;
809 case 1: type
= OUTPUT_TMDS
; break;
810 case 2: type
= OUTPUT_TMDS
; break;
811 case 5: type
= OUTPUT_TMDS
; break;
812 case 8: type
= OUTPUT_DP
; break;
813 case 9: type
= OUTPUT_DP
; break;
815 NV_ERROR(dev
, "invalid mc, SOR-%d: 0x%08x\n", i
, mc
);
822 if (type
== OUTPUT_ANY
)
825 /* Enable the encoder */
826 for (i
= 0; i
< dev_priv
->vbios
.dcb
.entries
; i
++) {
827 dcb
= &dev_priv
->vbios
.dcb
.entry
[i
];
828 if (dcb
->type
== type
&& (dcb
->or & (1 << or)))
832 if (i
== dev_priv
->vbios
.dcb
.entries
) {
833 NV_ERROR(dev
, "no dcb for %d %d 0x%08x\n", or, type
, mc
);
837 script
= nv50_display_script_select(dev
, dcb
, mc
, pclk
);
838 nouveau_bios_run_display_table(dev
, script
, pclk
, dcb
, -1);
840 if (type
== OUTPUT_DP
) {
841 int link
= !(dcb
->dpconf
.sor
.link
& 1);
842 if ((mc
& 0x000f0000) == 0x00020000)
843 nouveau_dp_tu_update(dev
, or, link
, pclk
, 18);
845 nouveau_dp_tu_update(dev
, or, link
, pclk
, 24);
848 if (dcb
->type
!= OUTPUT_ANALOG
) {
849 tmp
= nv_rd32(dev
, NV50_PDISPLAY_SOR_CLK_CTRL2(or));
853 nv_wr32(dev
, NV50_PDISPLAY_SOR_CLK_CTRL2(or), tmp
);
855 nv_wr32(dev
, NV50_PDISPLAY_DAC_CLK_CTRL2(or), 0);
859 disp
->irq
.pclk
= pclk
;
860 disp
->irq
.script
= script
;
863 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, NV50_PDISPLAY_INTR_1_CLK_UNK20
);
864 nv_wr32(dev
, 0x610030, 0x80000000);
867 /* If programming a TMDS output on a SOR that can also be configured for
868 * DisplayPort, make sure NV50_SOR_DP_CTRL_ENABLE is forced off.
870 * It looks like the VBIOS TMDS scripts make an attempt at this, however,
871 * the VBIOS scripts on at least one board I have only switch it off on
872 * link 0, causing a blank display if the output has previously been
873 * programmed for DisplayPort.
876 nv50_display_unk40_dp_set_tmds(struct drm_device
*dev
, struct dcb_entry
*dcb
)
878 int or = ffs(dcb
->or) - 1, link
= !(dcb
->dpconf
.sor
.link
& 1);
879 struct drm_encoder
*encoder
;
882 if (dcb
->type
!= OUTPUT_TMDS
)
885 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
886 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
888 if (nv_encoder
->dcb
->type
== OUTPUT_DP
&&
889 nv_encoder
->dcb
->or & (1 << or)) {
890 tmp
= nv_rd32(dev
, NV50_SOR_DP_CTRL(or, link
));
891 tmp
&= ~NV50_SOR_DP_CTRL_ENABLED
;
892 nv_wr32(dev
, NV50_SOR_DP_CTRL(or, link
), tmp
);
899 nv50_display_unk40_handler(struct drm_device
*dev
)
901 struct nv50_display
*disp
= nv50_display(dev
);
902 struct dcb_entry
*dcb
= disp
->irq
.dcb
;
903 u16 script
= disp
->irq
.script
;
904 u32 unk30
= nv_rd32(dev
, 0x610030), pclk
= disp
->irq
.pclk
;
906 NV_DEBUG_KMS(dev
, "0x610030: 0x%08x\n", unk30
);
907 disp
->irq
.dcb
= NULL
;
911 nouveau_bios_run_display_table(dev
, script
, -pclk
, dcb
, -1);
912 nv50_display_unk40_dp_set_tmds(dev
, dcb
);
915 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, NV50_PDISPLAY_INTR_1_CLK_UNK40
);
916 nv_wr32(dev
, 0x610030, 0x80000000);
917 nv_wr32(dev
, 0x619494, nv_rd32(dev
, 0x619494) | 8);
921 nv50_display_bh(unsigned long data
)
923 struct drm_device
*dev
= (struct drm_device
*)data
;
926 uint32_t intr0
= nv_rd32(dev
, NV50_PDISPLAY_INTR_0
);
927 uint32_t intr1
= nv_rd32(dev
, NV50_PDISPLAY_INTR_1
);
929 NV_DEBUG_KMS(dev
, "PDISPLAY_INTR_BH 0x%08x 0x%08x\n", intr0
, intr1
);
931 if (intr1
& NV50_PDISPLAY_INTR_1_CLK_UNK10
)
932 nv50_display_unk10_handler(dev
);
934 if (intr1
& NV50_PDISPLAY_INTR_1_CLK_UNK20
)
935 nv50_display_unk20_handler(dev
);
937 if (intr1
& NV50_PDISPLAY_INTR_1_CLK_UNK40
)
938 nv50_display_unk40_handler(dev
);
943 nv_wr32(dev
, NV03_PMC_INTR_EN_0
, 1);
947 nv50_display_error_handler(struct drm_device
*dev
)
949 u32 channels
= (nv_rd32(dev
, NV50_PDISPLAY_INTR_0
) & 0x001f0000) >> 16;
953 for (chid
= 0; chid
< 5; chid
++) {
954 if (!(channels
& (1 << chid
)))
957 nv_wr32(dev
, NV50_PDISPLAY_INTR_0
, 0x00010000 << chid
);
958 addr
= nv_rd32(dev
, NV50_PDISPLAY_TRAPPED_ADDR(chid
));
959 data
= nv_rd32(dev
, NV50_PDISPLAY_TRAPPED_DATA(chid
));
960 NV_ERROR(dev
, "EvoCh %d Mthd 0x%04x Data 0x%08x "
961 "(0x%04x 0x%02x)\n", chid
,
962 addr
& 0xffc, data
, addr
>> 16, (addr
>> 12) & 0xf);
964 nv_wr32(dev
, NV50_PDISPLAY_TRAPPED_ADDR(chid
), 0x90000000);
969 nv50_display_isr(struct drm_device
*dev
)
971 struct nv50_display
*disp
= nv50_display(dev
);
972 uint32_t delayed
= 0;
974 while (nv_rd32(dev
, NV50_PMC_INTR_0
) & NV50_PMC_INTR_0_DISPLAY
) {
975 uint32_t intr0
= nv_rd32(dev
, NV50_PDISPLAY_INTR_0
);
976 uint32_t intr1
= nv_rd32(dev
, NV50_PDISPLAY_INTR_1
);
979 NV_DEBUG_KMS(dev
, "PDISPLAY_INTR 0x%08x 0x%08x\n", intr0
, intr1
);
981 if (!intr0
&& !(intr1
& ~delayed
))
984 if (intr0
& 0x001f0000) {
985 nv50_display_error_handler(dev
);
986 intr0
&= ~0x001f0000;
989 if (intr1
& NV50_PDISPLAY_INTR_1_VBLANK_CRTC
) {
990 nv50_display_vblank_handler(dev
, intr1
);
991 intr1
&= ~NV50_PDISPLAY_INTR_1_VBLANK_CRTC
;
994 clock
= (intr1
& (NV50_PDISPLAY_INTR_1_CLK_UNK10
|
995 NV50_PDISPLAY_INTR_1_CLK_UNK20
|
996 NV50_PDISPLAY_INTR_1_CLK_UNK40
));
998 nv_wr32(dev
, NV03_PMC_INTR_EN_0
, 0);
999 tasklet_schedule(&disp
->tasklet
);
1005 NV_ERROR(dev
, "unknown PDISPLAY_INTR_0: 0x%08x\n", intr0
);
1006 nv_wr32(dev
, NV50_PDISPLAY_INTR_0
, intr0
);
1011 "unknown PDISPLAY_INTR_1: 0x%08x\n", intr1
);
1012 nv_wr32(dev
, NV50_PDISPLAY_INTR_1
, intr1
);