2 * Copyright 2011 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <linux/dma-mapping.h>
28 #include <drm/drm_crtc_helper.h>
30 #include "nouveau_drm.h"
31 #include "nouveau_dma.h"
32 #include "nouveau_gem.h"
33 #include "nouveau_connector.h"
34 #include "nouveau_encoder.h"
35 #include "nouveau_crtc.h"
36 #include "nouveau_fence.h"
37 #include "nv50_display.h"
39 #include <core/client.h>
40 #include <core/gpuobj.h>
41 #include <core/class.h>
43 #include <subdev/timer.h>
44 #include <subdev/bar.h>
45 #include <subdev/fb.h>
49 #define EVO_MASTER (0x00)
50 #define EVO_FLIP(c) (0x01 + (c))
51 #define EVO_OVLY(c) (0x05 + (c))
52 #define EVO_OIMM(c) (0x09 + (c))
53 #define EVO_CURS(c) (0x0d + (c))
55 /* offsets in shared sync bo of various structures */
56 #define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
57 #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
58 #define EVO_FLIP_SEM0(c) EVO_SYNC((c), 0x00)
59 #define EVO_FLIP_SEM1(c) EVO_SYNC((c), 0x10)
61 #define EVO_CORE_HANDLE (0xd1500000)
62 #define EVO_CHAN_HANDLE(t,i) (0xd15c0000 | (((t) & 0x00ff) << 8) | (i))
63 #define EVO_CHAN_OCLASS(t,c) ((nv_hclass(c) & 0xff00) | ((t) & 0x00ff))
64 #define EVO_PUSH_HANDLE(t,i) (0xd15b0000 | (i) | \
65 (((NV50_DISP_##t##_CLASS) & 0x00ff) << 8))
67 /******************************************************************************
69 *****************************************************************************/
72 struct nouveau_object
*user
;
77 nvd0_chan_create(struct nouveau_object
*core
, u32 bclass
, u8 head
,
78 void *data
, u32 size
, struct nvd0_chan
*chan
)
80 struct nouveau_object
*client
= nv_pclass(core
, NV_CLIENT_CLASS
);
81 const u32 oclass
= EVO_CHAN_OCLASS(bclass
, core
);
82 const u32 handle
= EVO_CHAN_HANDLE(bclass
, head
);
85 ret
= nouveau_object_new(client
, EVO_CORE_HANDLE
, handle
,
86 oclass
, data
, size
, &chan
->user
);
90 chan
->handle
= handle
;
95 nvd0_chan_destroy(struct nouveau_object
*core
, struct nvd0_chan
*chan
)
97 struct nouveau_object
*client
= nv_pclass(core
, NV_CLIENT_CLASS
);
99 nouveau_object_del(client
, EVO_CORE_HANDLE
, chan
->handle
);
102 /******************************************************************************
104 *****************************************************************************/
107 struct nvd0_chan base
;
111 nvd0_pioc_destroy(struct nouveau_object
*core
, struct nvd0_pioc
*pioc
)
113 nvd0_chan_destroy(core
, &pioc
->base
);
117 nvd0_pioc_create(struct nouveau_object
*core
, u32 bclass
, u8 head
,
118 void *data
, u32 size
, struct nvd0_pioc
*pioc
)
120 return nvd0_chan_create(core
, bclass
, head
, data
, size
, &pioc
->base
);
123 /******************************************************************************
125 *****************************************************************************/
128 struct nvd0_chan base
;
134 nvd0_dmac_destroy(struct nouveau_object
*core
, struct nvd0_dmac
*dmac
)
137 struct pci_dev
*pdev
= nv_device(core
)->pdev
;
138 pci_free_consistent(pdev
, PAGE_SIZE
, dmac
->ptr
, dmac
->handle
);
141 nvd0_chan_destroy(core
, &dmac
->base
);
145 nvd0_dmac_create(struct nouveau_object
*core
, u32 bclass
, u8 head
,
146 void *data
, u32 size
, u64 syncbuf
,
147 struct nvd0_dmac
*dmac
)
149 struct nouveau_fb
*pfb
= nouveau_fb(core
);
150 struct nouveau_object
*client
= nv_pclass(core
, NV_CLIENT_CLASS
);
151 struct nouveau_object
*object
;
152 u32 pushbuf
= *(u32
*)data
;
157 ptr
= pci_alloc_consistent(nv_device(core
)->pdev
, PAGE_SIZE
, &handle
);
161 ret
= nouveau_object_new(client
, NVDRM_DEVICE
, pushbuf
,
162 NV_DMA_FROM_MEMORY_CLASS
,
163 &(struct nv_dma_class
) {
164 .flags
= NV_DMA_TARGET_PCI_US
|
166 .start
= handle
+ 0x0000,
167 .limit
= handle
+ 0x0fff,
168 }, sizeof(struct nv_dma_class
), &object
);
172 ret
= nvd0_chan_create(core
, bclass
, head
, data
, size
, &dmac
->base
);
176 dmac
->handle
= handle
;
179 ret
= nouveau_object_new(client
, dmac
->base
.handle
, NvEvoSync
,
180 NV_DMA_IN_MEMORY_CLASS
,
181 &(struct nv_dma_class
) {
182 .flags
= NV_DMA_TARGET_VRAM
|
184 .start
= syncbuf
+ 0x0000,
185 .limit
= syncbuf
+ 0x0fff,
186 }, sizeof(struct nv_dma_class
), &object
);
190 ret
= nouveau_object_new(client
, dmac
->base
.handle
, NvEvoVRAM
,
191 NV_DMA_IN_MEMORY_CLASS
,
192 &(struct nv_dma_class
) {
193 .flags
= NV_DMA_TARGET_VRAM
|
196 .limit
= pfb
->ram
.size
- 1,
197 }, sizeof(struct nv_dma_class
), &object
);
201 ret
= nouveau_object_new(client
, dmac
->base
.handle
, NvEvoVRAM_LP
,
202 NV_DMA_IN_MEMORY_CLASS
,
203 &(struct nv_dma_class
) {
204 .flags
= NV_DMA_TARGET_VRAM
|
207 .limit
= pfb
->ram
.size
- 1,
208 .conf0
= NVD0_DMA_CONF0_ENABLE
|
209 NVD0_DMA_CONF0_PAGE_LP
,
210 }, sizeof(struct nv_dma_class
), &object
);
214 ret
= nouveau_object_new(client
, dmac
->base
.handle
, NvEvoFB32
,
215 NV_DMA_IN_MEMORY_CLASS
,
216 &(struct nv_dma_class
) {
217 .flags
= NV_DMA_TARGET_VRAM
|
220 .limit
= pfb
->ram
.size
- 1,
222 NVD0_DMA_CONF0_ENABLE
|
223 NVD0_DMA_CONF0_PAGE_LP
,
224 }, sizeof(struct nv_dma_class
), &object
);
227 nvd0_dmac_destroy(core
, dmac
);
232 struct nvd0_dmac base
;
236 struct nvd0_pioc base
;
240 struct nvd0_dmac base
;
248 struct nvd0_dmac base
;
252 struct nvd0_pioc base
;
256 struct nouveau_crtc base
;
257 struct nvd0_curs curs
;
258 struct nvd0_sync sync
;
259 struct nvd0_ovly ovly
;
260 struct nvd0_oimm oimm
;
263 #define nvd0_head(c) ((struct nvd0_head *)nouveau_crtc(c))
264 #define nvd0_curs(c) (&nvd0_head(c)->curs)
265 #define nvd0_sync(c) (&nvd0_head(c)->sync)
266 #define nvd0_ovly(c) (&nvd0_head(c)->ovly)
267 #define nvd0_oimm(c) (&nvd0_head(c)->oimm)
268 #define nvd0_chan(c) (&(c)->base.base)
271 struct nouveau_object
*core
;
272 struct nvd0_mast mast
;
276 struct nouveau_bo
*sync
;
279 static struct nvd0_disp
*
280 nvd0_disp(struct drm_device
*dev
)
282 return nouveau_display(dev
)->priv
;
285 #define nvd0_mast(d) (&nvd0_disp(d)->mast)
287 static struct drm_crtc
*
288 nvd0_display_crtc_get(struct drm_encoder
*encoder
)
290 return nouveau_encoder(encoder
)->crtc
;
293 /******************************************************************************
294 * EVO channel helpers
295 *****************************************************************************/
297 evo_wait(void *evoc
, int nr
)
299 struct nvd0_dmac
*dmac
= evoc
;
300 u32 put
= nv_ro32(dmac
->base
.user
, 0x0000) / 4;
302 if (put
+ nr
>= (PAGE_SIZE
/ 4)) {
303 dmac
->ptr
[put
] = 0x20000000;
305 nv_wo32(dmac
->base
.user
, 0x0000, 0x00000000);
306 if (!nv_wait(dmac
->base
.user
, 0x0004, ~0, 0x00000000)) {
307 NV_ERROR(dmac
->base
.user
, "channel stalled\n");
314 return dmac
->ptr
+ put
;
318 evo_kick(u32
*push
, void *evoc
)
320 struct nvd0_dmac
*dmac
= evoc
;
321 nv_wo32(dmac
->base
.user
, 0x0000, (push
- dmac
->ptr
) << 2);
324 #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
325 #define evo_data(p,d) *((p)++) = (d)
328 evo_sync_wait(void *data
)
330 return nouveau_bo_rd32(data
, EVO_MAST_NTFY
) != 0x00000000;
334 evo_sync(struct drm_device
*dev
)
336 struct nouveau_device
*device
= nouveau_dev(dev
);
337 struct nvd0_disp
*disp
= nvd0_disp(dev
);
338 struct nvd0_mast
*mast
= nvd0_mast(dev
);
339 u32
*push
= evo_wait(mast
, 8);
341 nouveau_bo_wr32(disp
->sync
, EVO_MAST_NTFY
, 0x00000000);
342 evo_mthd(push
, 0x0084, 1);
343 evo_data(push
, 0x80000000 | EVO_MAST_NTFY
);
344 evo_mthd(push
, 0x0080, 2);
345 evo_data(push
, 0x00000000);
346 evo_data(push
, 0x00000000);
347 evo_kick(push
, mast
);
348 if (nv_wait_cb(device
, evo_sync_wait
, disp
->sync
))
355 /******************************************************************************
356 * Page flipping channel
357 *****************************************************************************/
359 nvd0_display_crtc_sema(struct drm_device
*dev
, int crtc
)
361 return nvd0_disp(dev
)->sync
;
365 nvd0_display_flip_stop(struct drm_crtc
*crtc
)
367 struct nvd0_sync
*sync
= nvd0_sync(crtc
);
370 push
= evo_wait(sync
, 8);
372 evo_mthd(push
, 0x0084, 1);
373 evo_data(push
, 0x00000000);
374 evo_mthd(push
, 0x0094, 1);
375 evo_data(push
, 0x00000000);
376 evo_mthd(push
, 0x00c0, 1);
377 evo_data(push
, 0x00000000);
378 evo_mthd(push
, 0x0080, 1);
379 evo_data(push
, 0x00000000);
380 evo_kick(push
, sync
);
385 nvd0_display_flip_next(struct drm_crtc
*crtc
, struct drm_framebuffer
*fb
,
386 struct nouveau_channel
*chan
, u32 swap_interval
)
388 struct nouveau_framebuffer
*nv_fb
= nouveau_framebuffer(fb
);
389 struct nvd0_disp
*disp
= nvd0_disp(crtc
->dev
);
390 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
391 struct nvd0_sync
*sync
= nvd0_sync(crtc
);
397 if (swap_interval
== 0)
398 swap_interval
|= 0x100;
400 push
= evo_wait(sync
, 128);
401 if (unlikely(push
== NULL
))
404 /* synchronise with the rendering channel, if necessary */
406 ret
= RING_SPACE(chan
, 10);
411 offset
= nvc0_fence_crtc(chan
, nv_crtc
->index
);
412 offset
+= sync
->sem
.offset
;
414 BEGIN_NVC0(chan
, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH
, 4);
415 OUT_RING (chan
, upper_32_bits(offset
));
416 OUT_RING (chan
, lower_32_bits(offset
));
417 OUT_RING (chan
, 0xf00d0000 | sync
->sem
.value
);
418 OUT_RING (chan
, 0x1002);
419 BEGIN_NVC0(chan
, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH
, 4);
420 OUT_RING (chan
, upper_32_bits(offset
));
421 OUT_RING (chan
, lower_32_bits(offset
^ 0x10));
422 OUT_RING (chan
, 0x74b1e000);
423 OUT_RING (chan
, 0x1001);
426 nouveau_bo_wr32(disp
->sync
, sync
->sem
.offset
/ 4,
427 0xf00d0000 | sync
->sem
.value
);
432 evo_mthd(push
, 0x0100, 1);
433 evo_data(push
, 0xfffe0000);
434 evo_mthd(push
, 0x0084, 1);
435 evo_data(push
, swap_interval
);
436 if (!(swap_interval
& 0x00000100)) {
437 evo_mthd(push
, 0x00e0, 1);
438 evo_data(push
, 0x40000000);
440 evo_mthd(push
, 0x0088, 4);
441 evo_data(push
, sync
->sem
.offset
);
442 evo_data(push
, 0xf00d0000 | sync
->sem
.value
);
443 evo_data(push
, 0x74b1e000);
444 evo_data(push
, NvEvoSync
);
445 evo_mthd(push
, 0x00a0, 2);
446 evo_data(push
, 0x00000000);
447 evo_data(push
, 0x00000000);
448 evo_mthd(push
, 0x00c0, 1);
449 evo_data(push
, nv_fb
->r_dma
);
450 evo_mthd(push
, 0x0110, 2);
451 evo_data(push
, 0x00000000);
452 evo_data(push
, 0x00000000);
453 evo_mthd(push
, 0x0400, 5);
454 evo_data(push
, nv_fb
->nvbo
->bo
.offset
>> 8);
456 evo_data(push
, (fb
->height
<< 16) | fb
->width
);
457 evo_data(push
, nv_fb
->r_pitch
);
458 evo_data(push
, nv_fb
->r_format
);
459 evo_mthd(push
, 0x0080, 1);
460 evo_data(push
, 0x00000000);
461 evo_kick(push
, sync
);
463 sync
->sem
.offset
^= 0x10;
468 /******************************************************************************
470 *****************************************************************************/
472 nvd0_crtc_set_dither(struct nouveau_crtc
*nv_crtc
, bool update
)
474 struct nouveau_drm
*drm
= nouveau_drm(nv_crtc
->base
.dev
);
475 struct drm_device
*dev
= nv_crtc
->base
.dev
;
476 struct nouveau_connector
*nv_connector
;
477 struct drm_connector
*connector
;
478 u32
*push
, mode
= 0x00;
481 nv_connector
= nouveau_crtc_connector_get(nv_crtc
);
482 connector
= &nv_connector
->base
;
483 if (nv_connector
->dithering_mode
== DITHERING_MODE_AUTO
) {
484 if (nv_crtc
->base
.fb
->depth
> connector
->display_info
.bpc
* 3)
485 mode
= DITHERING_MODE_DYNAMIC2X2
;
487 mode
= nv_connector
->dithering_mode
;
490 if (nv_connector
->dithering_depth
== DITHERING_DEPTH_AUTO
) {
491 if (connector
->display_info
.bpc
>= 8)
492 mode
|= DITHERING_DEPTH_8BPC
;
494 mode
|= nv_connector
->dithering_depth
;
497 if (nv_device(drm
->device
)->card_type
< NV_E0
)
498 mthd
= 0x0490 + (nv_crtc
->index
* 0x0300);
500 mthd
= 0x04a0 + (nv_crtc
->index
* 0x0300);
502 push
= evo_wait(nvd0_mast(dev
), 4);
504 evo_mthd(push
, mthd
, 1);
505 evo_data(push
, mode
);
507 evo_mthd(push
, 0x0080, 1);
508 evo_data(push
, 0x00000000);
510 evo_kick(push
, nvd0_mast(dev
));
517 nvd0_crtc_set_scale(struct nouveau_crtc
*nv_crtc
, bool update
)
519 struct drm_display_mode
*omode
, *umode
= &nv_crtc
->base
.mode
;
520 struct drm_device
*dev
= nv_crtc
->base
.dev
;
521 struct drm_crtc
*crtc
= &nv_crtc
->base
;
522 struct nouveau_connector
*nv_connector
;
523 int mode
= DRM_MODE_SCALE_NONE
;
526 /* start off at the resolution we programmed the crtc for, this
527 * effectively handles NONE/FULL scaling
529 nv_connector
= nouveau_crtc_connector_get(nv_crtc
);
530 if (nv_connector
&& nv_connector
->native_mode
)
531 mode
= nv_connector
->scaling_mode
;
533 if (mode
!= DRM_MODE_SCALE_NONE
)
534 omode
= nv_connector
->native_mode
;
538 oX
= omode
->hdisplay
;
539 oY
= omode
->vdisplay
;
540 if (omode
->flags
& DRM_MODE_FLAG_DBLSCAN
)
543 /* add overscan compensation if necessary, will keep the aspect
544 * ratio the same as the backend mode unless overridden by the
545 * user setting both hborder and vborder properties.
547 if (nv_connector
&& ( nv_connector
->underscan
== UNDERSCAN_ON
||
548 (nv_connector
->underscan
== UNDERSCAN_AUTO
&&
549 nv_connector
->edid
&&
550 drm_detect_hdmi_monitor(nv_connector
->edid
)))) {
551 u32 bX
= nv_connector
->underscan_hborder
;
552 u32 bY
= nv_connector
->underscan_vborder
;
553 u32 aspect
= (oY
<< 19) / oX
;
557 if (bY
) oY
-= (bY
* 2);
558 else oY
= ((oX
* aspect
) + (aspect
/ 2)) >> 19;
560 oX
-= (oX
>> 4) + 32;
561 if (bY
) oY
-= (bY
* 2);
562 else oY
= ((oX
* aspect
) + (aspect
/ 2)) >> 19;
566 /* handle CENTER/ASPECT scaling, taking into account the areas
567 * removed already for overscan compensation
570 case DRM_MODE_SCALE_CENTER
:
571 oX
= min((u32
)umode
->hdisplay
, oX
);
572 oY
= min((u32
)umode
->vdisplay
, oY
);
574 case DRM_MODE_SCALE_ASPECT
:
576 u32 aspect
= (umode
->hdisplay
<< 19) / umode
->vdisplay
;
577 oX
= ((oY
* aspect
) + (aspect
/ 2)) >> 19;
579 u32 aspect
= (umode
->vdisplay
<< 19) / umode
->hdisplay
;
580 oY
= ((oX
* aspect
) + (aspect
/ 2)) >> 19;
587 push
= evo_wait(nvd0_mast(dev
), 8);
589 evo_mthd(push
, 0x04c0 + (nv_crtc
->index
* 0x300), 3);
590 evo_data(push
, (oY
<< 16) | oX
);
591 evo_data(push
, (oY
<< 16) | oX
);
592 evo_data(push
, (oY
<< 16) | oX
);
593 evo_mthd(push
, 0x0494 + (nv_crtc
->index
* 0x300), 1);
594 evo_data(push
, 0x00000000);
595 evo_mthd(push
, 0x04b8 + (nv_crtc
->index
* 0x300), 1);
596 evo_data(push
, (umode
->vdisplay
<< 16) | umode
->hdisplay
);
597 evo_kick(push
, nvd0_mast(dev
));
599 nvd0_display_flip_stop(crtc
);
600 nvd0_display_flip_next(crtc
, crtc
->fb
, NULL
, 1);
608 nvd0_crtc_set_image(struct nouveau_crtc
*nv_crtc
, struct drm_framebuffer
*fb
,
609 int x
, int y
, bool update
)
611 struct nouveau_framebuffer
*nvfb
= nouveau_framebuffer(fb
);
614 push
= evo_wait(nvd0_mast(fb
->dev
), 16);
616 evo_mthd(push
, 0x0460 + (nv_crtc
->index
* 0x300), 1);
617 evo_data(push
, nvfb
->nvbo
->bo
.offset
>> 8);
618 evo_mthd(push
, 0x0468 + (nv_crtc
->index
* 0x300), 4);
619 evo_data(push
, (fb
->height
<< 16) | fb
->width
);
620 evo_data(push
, nvfb
->r_pitch
);
621 evo_data(push
, nvfb
->r_format
);
622 evo_data(push
, nvfb
->r_dma
);
623 evo_mthd(push
, 0x04b0 + (nv_crtc
->index
* 0x300), 1);
624 evo_data(push
, (y
<< 16) | x
);
626 evo_mthd(push
, 0x0080, 1);
627 evo_data(push
, 0x00000000);
629 evo_kick(push
, nvd0_mast(fb
->dev
));
632 nv_crtc
->fb
.tile_flags
= nvfb
->r_dma
;
637 nvd0_crtc_cursor_show(struct nouveau_crtc
*nv_crtc
, bool show
, bool update
)
639 struct drm_device
*dev
= nv_crtc
->base
.dev
;
640 u32
*push
= evo_wait(nvd0_mast(dev
), 16);
643 evo_mthd(push
, 0x0480 + (nv_crtc
->index
* 0x300), 2);
644 evo_data(push
, 0x85000000);
645 evo_data(push
, nv_crtc
->cursor
.nvbo
->bo
.offset
>> 8);
646 evo_mthd(push
, 0x048c + (nv_crtc
->index
* 0x300), 1);
647 evo_data(push
, NvEvoVRAM
);
649 evo_mthd(push
, 0x0480 + (nv_crtc
->index
* 0x300), 1);
650 evo_data(push
, 0x05000000);
651 evo_mthd(push
, 0x048c + (nv_crtc
->index
* 0x300), 1);
652 evo_data(push
, 0x00000000);
656 evo_mthd(push
, 0x0080, 1);
657 evo_data(push
, 0x00000000);
660 evo_kick(push
, nvd0_mast(dev
));
665 nvd0_crtc_dpms(struct drm_crtc
*crtc
, int mode
)
670 nvd0_crtc_prepare(struct drm_crtc
*crtc
)
672 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
675 nvd0_display_flip_stop(crtc
);
677 push
= evo_wait(nvd0_mast(crtc
->dev
), 2);
679 evo_mthd(push
, 0x0474 + (nv_crtc
->index
* 0x300), 1);
680 evo_data(push
, 0x00000000);
681 evo_mthd(push
, 0x0440 + (nv_crtc
->index
* 0x300), 1);
682 evo_data(push
, 0x03000000);
683 evo_mthd(push
, 0x045c + (nv_crtc
->index
* 0x300), 1);
684 evo_data(push
, 0x00000000);
685 evo_kick(push
, nvd0_mast(crtc
->dev
));
688 nvd0_crtc_cursor_show(nv_crtc
, false, false);
692 nvd0_crtc_commit(struct drm_crtc
*crtc
)
694 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
697 push
= evo_wait(nvd0_mast(crtc
->dev
), 32);
699 evo_mthd(push
, 0x0474 + (nv_crtc
->index
* 0x300), 1);
700 evo_data(push
, nv_crtc
->fb
.tile_flags
);
701 evo_mthd(push
, 0x0440 + (nv_crtc
->index
* 0x300), 4);
702 evo_data(push
, 0x83000000);
703 evo_data(push
, nv_crtc
->lut
.nvbo
->bo
.offset
>> 8);
704 evo_data(push
, 0x00000000);
705 evo_data(push
, 0x00000000);
706 evo_mthd(push
, 0x045c + (nv_crtc
->index
* 0x300), 1);
707 evo_data(push
, NvEvoVRAM
);
708 evo_mthd(push
, 0x0430 + (nv_crtc
->index
* 0x300), 1);
709 evo_data(push
, 0xffffff00);
710 evo_kick(push
, nvd0_mast(crtc
->dev
));
713 nvd0_crtc_cursor_show(nv_crtc
, nv_crtc
->cursor
.visible
, true);
714 nvd0_display_flip_next(crtc
, crtc
->fb
, NULL
, 1);
718 nvd0_crtc_mode_fixup(struct drm_crtc
*crtc
, const struct drm_display_mode
*mode
,
719 struct drm_display_mode
*adjusted_mode
)
725 nvd0_crtc_swap_fbs(struct drm_crtc
*crtc
, struct drm_framebuffer
*old_fb
)
727 struct nouveau_framebuffer
*nvfb
= nouveau_framebuffer(crtc
->fb
);
730 ret
= nouveau_bo_pin(nvfb
->nvbo
, TTM_PL_FLAG_VRAM
);
735 nvfb
= nouveau_framebuffer(old_fb
);
736 nouveau_bo_unpin(nvfb
->nvbo
);
743 nvd0_crtc_mode_set(struct drm_crtc
*crtc
, struct drm_display_mode
*umode
,
744 struct drm_display_mode
*mode
, int x
, int y
,
745 struct drm_framebuffer
*old_fb
)
747 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
748 struct nouveau_connector
*nv_connector
;
749 u32 ilace
= (mode
->flags
& DRM_MODE_FLAG_INTERLACE
) ? 2 : 1;
750 u32 vscan
= (mode
->flags
& DRM_MODE_FLAG_DBLSCAN
) ? 2 : 1;
751 u32 hactive
, hsynce
, hbackp
, hfrontp
, hblanke
, hblanks
;
752 u32 vactive
, vsynce
, vbackp
, vfrontp
, vblanke
, vblanks
;
753 u32 vblan2e
= 0, vblan2s
= 1;
757 hactive
= mode
->htotal
;
758 hsynce
= mode
->hsync_end
- mode
->hsync_start
- 1;
759 hbackp
= mode
->htotal
- mode
->hsync_end
;
760 hblanke
= hsynce
+ hbackp
;
761 hfrontp
= mode
->hsync_start
- mode
->hdisplay
;
762 hblanks
= mode
->htotal
- hfrontp
- 1;
764 vactive
= mode
->vtotal
* vscan
/ ilace
;
765 vsynce
= ((mode
->vsync_end
- mode
->vsync_start
) * vscan
/ ilace
) - 1;
766 vbackp
= (mode
->vtotal
- mode
->vsync_end
) * vscan
/ ilace
;
767 vblanke
= vsynce
+ vbackp
;
768 vfrontp
= (mode
->vsync_start
- mode
->vdisplay
) * vscan
/ ilace
;
769 vblanks
= vactive
- vfrontp
- 1;
770 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
771 vblan2e
= vactive
+ vsynce
+ vbackp
;
772 vblan2s
= vblan2e
+ (mode
->vdisplay
* vscan
/ ilace
);
773 vactive
= (vactive
* 2) + 1;
776 ret
= nvd0_crtc_swap_fbs(crtc
, old_fb
);
780 push
= evo_wait(nvd0_mast(crtc
->dev
), 64);
782 evo_mthd(push
, 0x0410 + (nv_crtc
->index
* 0x300), 6);
783 evo_data(push
, 0x00000000);
784 evo_data(push
, (vactive
<< 16) | hactive
);
785 evo_data(push
, ( vsynce
<< 16) | hsynce
);
786 evo_data(push
, (vblanke
<< 16) | hblanke
);
787 evo_data(push
, (vblanks
<< 16) | hblanks
);
788 evo_data(push
, (vblan2e
<< 16) | vblan2s
);
789 evo_mthd(push
, 0x042c + (nv_crtc
->index
* 0x300), 1);
790 evo_data(push
, 0x00000000); /* ??? */
791 evo_mthd(push
, 0x0450 + (nv_crtc
->index
* 0x300), 3);
792 evo_data(push
, mode
->clock
* 1000);
793 evo_data(push
, 0x00200000); /* ??? */
794 evo_data(push
, mode
->clock
* 1000);
795 evo_mthd(push
, 0x04d0 + (nv_crtc
->index
* 0x300), 2);
796 evo_data(push
, 0x00000311);
797 evo_data(push
, 0x00000100);
798 evo_kick(push
, nvd0_mast(crtc
->dev
));
801 nv_connector
= nouveau_crtc_connector_get(nv_crtc
);
802 nvd0_crtc_set_dither(nv_crtc
, false);
803 nvd0_crtc_set_scale(nv_crtc
, false);
804 nvd0_crtc_set_image(nv_crtc
, crtc
->fb
, x
, y
, false);
809 nvd0_crtc_mode_set_base(struct drm_crtc
*crtc
, int x
, int y
,
810 struct drm_framebuffer
*old_fb
)
812 struct nouveau_drm
*drm
= nouveau_drm(crtc
->dev
);
813 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
817 NV_DEBUG(drm
, "No FB bound\n");
821 ret
= nvd0_crtc_swap_fbs(crtc
, old_fb
);
825 nvd0_display_flip_stop(crtc
);
826 nvd0_crtc_set_image(nv_crtc
, crtc
->fb
, x
, y
, true);
827 nvd0_display_flip_next(crtc
, crtc
->fb
, NULL
, 1);
832 nvd0_crtc_mode_set_base_atomic(struct drm_crtc
*crtc
,
833 struct drm_framebuffer
*fb
, int x
, int y
,
834 enum mode_set_atomic state
)
836 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
837 nvd0_display_flip_stop(crtc
);
838 nvd0_crtc_set_image(nv_crtc
, fb
, x
, y
, true);
843 nvd0_crtc_lut_load(struct drm_crtc
*crtc
)
845 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
846 void __iomem
*lut
= nvbo_kmap_obj_iovirtual(nv_crtc
->lut
.nvbo
);
849 for (i
= 0; i
< 256; i
++) {
850 writew(0x6000 + (nv_crtc
->lut
.r
[i
] >> 2), lut
+ (i
* 0x20) + 0);
851 writew(0x6000 + (nv_crtc
->lut
.g
[i
] >> 2), lut
+ (i
* 0x20) + 2);
852 writew(0x6000 + (nv_crtc
->lut
.b
[i
] >> 2), lut
+ (i
* 0x20) + 4);
857 nvd0_crtc_cursor_set(struct drm_crtc
*crtc
, struct drm_file
*file_priv
,
858 uint32_t handle
, uint32_t width
, uint32_t height
)
860 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
861 struct drm_device
*dev
= crtc
->dev
;
862 struct drm_gem_object
*gem
;
863 struct nouveau_bo
*nvbo
;
864 bool visible
= (handle
!= 0);
868 if (width
!= 64 || height
!= 64)
871 gem
= drm_gem_object_lookup(dev
, file_priv
, handle
);
874 nvbo
= nouveau_gem_object(gem
);
876 ret
= nouveau_bo_map(nvbo
);
878 for (i
= 0; i
< 64 * 64; i
++) {
879 u32 v
= nouveau_bo_rd32(nvbo
, i
);
880 nouveau_bo_wr32(nv_crtc
->cursor
.nvbo
, i
, v
);
882 nouveau_bo_unmap(nvbo
);
885 drm_gem_object_unreference_unlocked(gem
);
888 if (visible
!= nv_crtc
->cursor
.visible
) {
889 nvd0_crtc_cursor_show(nv_crtc
, visible
, true);
890 nv_crtc
->cursor
.visible
= visible
;
897 nvd0_crtc_cursor_move(struct drm_crtc
*crtc
, int x
, int y
)
899 struct nvd0_curs
*curs
= nvd0_curs(crtc
);
900 struct nvd0_chan
*chan
= nvd0_chan(curs
);
901 nv_wo32(chan
->user
, 0x0084, (y
<< 16) | (x
& 0xffff));
902 nv_wo32(chan
->user
, 0x0080, 0x00000000);
907 nvd0_crtc_gamma_set(struct drm_crtc
*crtc
, u16
*r
, u16
*g
, u16
*b
,
908 uint32_t start
, uint32_t size
)
910 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
911 u32 end
= max(start
+ size
, (u32
)256);
914 for (i
= start
; i
< end
; i
++) {
915 nv_crtc
->lut
.r
[i
] = r
[i
];
916 nv_crtc
->lut
.g
[i
] = g
[i
];
917 nv_crtc
->lut
.b
[i
] = b
[i
];
920 nvd0_crtc_lut_load(crtc
);
924 nvd0_crtc_destroy(struct drm_crtc
*crtc
)
926 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(crtc
);
927 struct nvd0_disp
*disp
= nvd0_disp(crtc
->dev
);
928 struct nvd0_head
*head
= nvd0_head(crtc
);
929 nvd0_dmac_destroy(disp
->core
, &head
->ovly
.base
);
930 nvd0_pioc_destroy(disp
->core
, &head
->oimm
.base
);
931 nvd0_dmac_destroy(disp
->core
, &head
->sync
.base
);
932 nvd0_pioc_destroy(disp
->core
, &head
->curs
.base
);
933 nouveau_bo_unmap(nv_crtc
->cursor
.nvbo
);
934 nouveau_bo_ref(NULL
, &nv_crtc
->cursor
.nvbo
);
935 nouveau_bo_unmap(nv_crtc
->lut
.nvbo
);
936 nouveau_bo_ref(NULL
, &nv_crtc
->lut
.nvbo
);
937 drm_crtc_cleanup(crtc
);
941 static const struct drm_crtc_helper_funcs nvd0_crtc_hfunc
= {
942 .dpms
= nvd0_crtc_dpms
,
943 .prepare
= nvd0_crtc_prepare
,
944 .commit
= nvd0_crtc_commit
,
945 .mode_fixup
= nvd0_crtc_mode_fixup
,
946 .mode_set
= nvd0_crtc_mode_set
,
947 .mode_set_base
= nvd0_crtc_mode_set_base
,
948 .mode_set_base_atomic
= nvd0_crtc_mode_set_base_atomic
,
949 .load_lut
= nvd0_crtc_lut_load
,
952 static const struct drm_crtc_funcs nvd0_crtc_func
= {
953 .cursor_set
= nvd0_crtc_cursor_set
,
954 .cursor_move
= nvd0_crtc_cursor_move
,
955 .gamma_set
= nvd0_crtc_gamma_set
,
956 .set_config
= drm_crtc_helper_set_config
,
957 .destroy
= nvd0_crtc_destroy
,
958 .page_flip
= nouveau_crtc_page_flip
,
962 nvd0_cursor_set_pos(struct nouveau_crtc
*nv_crtc
, int x
, int y
)
967 nvd0_cursor_set_offset(struct nouveau_crtc
*nv_crtc
, uint32_t offset
)
972 nvd0_crtc_create(struct drm_device
*dev
, struct nouveau_object
*core
, int index
)
974 struct nvd0_disp
*disp
= nvd0_disp(dev
);
975 struct nvd0_head
*head
;
976 struct drm_crtc
*crtc
;
979 head
= kzalloc(sizeof(*head
), GFP_KERNEL
);
983 head
->base
.index
= index
;
984 head
->base
.set_dither
= nvd0_crtc_set_dither
;
985 head
->base
.set_scale
= nvd0_crtc_set_scale
;
986 head
->base
.cursor
.set_offset
= nvd0_cursor_set_offset
;
987 head
->base
.cursor
.set_pos
= nvd0_cursor_set_pos
;
988 for (i
= 0; i
< 256; i
++) {
989 head
->base
.lut
.r
[i
] = i
<< 8;
990 head
->base
.lut
.g
[i
] = i
<< 8;
991 head
->base
.lut
.b
[i
] = i
<< 8;
994 crtc
= &head
->base
.base
;
995 drm_crtc_init(dev
, crtc
, &nvd0_crtc_func
);
996 drm_crtc_helper_add(crtc
, &nvd0_crtc_hfunc
);
997 drm_mode_crtc_set_gamma_size(crtc
, 256);
999 ret
= nouveau_bo_new(dev
, 8192, 0x100, TTM_PL_FLAG_VRAM
,
1000 0, 0x0000, NULL
, &head
->base
.lut
.nvbo
);
1002 ret
= nouveau_bo_pin(head
->base
.lut
.nvbo
, TTM_PL_FLAG_VRAM
);
1004 ret
= nouveau_bo_map(head
->base
.lut
.nvbo
);
1006 nouveau_bo_ref(NULL
, &head
->base
.lut
.nvbo
);
1012 nvd0_crtc_lut_load(crtc
);
1014 /* allocate cursor resources */
1015 ret
= nvd0_pioc_create(disp
->core
, NV50_DISP_CURS_CLASS
, index
,
1016 &(struct nv50_display_curs_class
) {
1018 }, sizeof(struct nv50_display_curs_class
),
1023 ret
= nouveau_bo_new(dev
, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM
,
1024 0, 0x0000, NULL
, &head
->base
.cursor
.nvbo
);
1026 ret
= nouveau_bo_pin(head
->base
.cursor
.nvbo
, TTM_PL_FLAG_VRAM
);
1028 ret
= nouveau_bo_map(head
->base
.cursor
.nvbo
);
1030 nouveau_bo_ref(NULL
, &head
->base
.cursor
.nvbo
);
1036 /* allocate page flip / sync resources */
1037 ret
= nvd0_dmac_create(disp
->core
, NV50_DISP_SYNC_CLASS
, index
,
1038 &(struct nv50_display_sync_class
) {
1039 .pushbuf
= EVO_PUSH_HANDLE(SYNC
, index
),
1041 }, sizeof(struct nv50_display_sync_class
),
1042 disp
->sync
->bo
.offset
, &head
->sync
.base
);
1046 head
->sync
.sem
.offset
= EVO_SYNC(1 + index
, 0x00);
1048 /* allocate overlay resources */
1049 ret
= nvd0_pioc_create(disp
->core
, NV50_DISP_OIMM_CLASS
, index
,
1050 &(struct nv50_display_oimm_class
) {
1052 }, sizeof(struct nv50_display_oimm_class
),
1057 ret
= nvd0_dmac_create(disp
->core
, NV50_DISP_OVLY_CLASS
, index
,
1058 &(struct nv50_display_ovly_class
) {
1059 .pushbuf
= EVO_PUSH_HANDLE(OVLY
, index
),
1061 }, sizeof(struct nv50_display_ovly_class
),
1062 disp
->sync
->bo
.offset
, &head
->ovly
.base
);
1068 nvd0_crtc_destroy(crtc
);
1072 /******************************************************************************
1074 *****************************************************************************/
1076 nvd0_dac_dpms(struct drm_encoder
*encoder
, int mode
)
1078 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1079 struct nvd0_disp
*disp
= nvd0_disp(encoder
->dev
);
1080 int or = nv_encoder
->or;
1083 dpms_ctrl
= 0x00000000;
1084 if (mode
== DRM_MODE_DPMS_STANDBY
|| mode
== DRM_MODE_DPMS_OFF
)
1085 dpms_ctrl
|= 0x00000001;
1086 if (mode
== DRM_MODE_DPMS_SUSPEND
|| mode
== DRM_MODE_DPMS_OFF
)
1087 dpms_ctrl
|= 0x00000004;
1089 nv_call(disp
->core
, NV50_DISP_DAC_PWR
+ or, dpms_ctrl
);
1093 nvd0_dac_mode_fixup(struct drm_encoder
*encoder
,
1094 const struct drm_display_mode
*mode
,
1095 struct drm_display_mode
*adjusted_mode
)
1097 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1098 struct nouveau_connector
*nv_connector
;
1100 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
1101 if (nv_connector
&& nv_connector
->native_mode
) {
1102 if (nv_connector
->scaling_mode
!= DRM_MODE_SCALE_NONE
) {
1103 int id
= adjusted_mode
->base
.id
;
1104 *adjusted_mode
= *nv_connector
->native_mode
;
1105 adjusted_mode
->base
.id
= id
;
1113 nvd0_dac_commit(struct drm_encoder
*encoder
)
1118 nvd0_dac_mode_set(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
,
1119 struct drm_display_mode
*adjusted_mode
)
1121 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1122 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
1123 u32 syncs
, magic
, *push
;
1126 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
1127 syncs
|= 0x00000008;
1128 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
1129 syncs
|= 0x00000010;
1131 magic
= 0x31ec6000 | (nv_crtc
->index
<< 25);
1132 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1133 magic
|= 0x00000001;
1135 nvd0_dac_dpms(encoder
, DRM_MODE_DPMS_ON
);
1137 push
= evo_wait(nvd0_mast(encoder
->dev
), 8);
1139 evo_mthd(push
, 0x0404 + (nv_crtc
->index
* 0x300), 2);
1140 evo_data(push
, syncs
);
1141 evo_data(push
, magic
);
1142 evo_mthd(push
, 0x0180 + (nv_encoder
->or * 0x020), 2);
1143 evo_data(push
, 1 << nv_crtc
->index
);
1144 evo_data(push
, 0x00ff);
1145 evo_kick(push
, nvd0_mast(encoder
->dev
));
1148 nv_encoder
->crtc
= encoder
->crtc
;
1152 nvd0_dac_disconnect(struct drm_encoder
*encoder
)
1154 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1155 struct drm_device
*dev
= encoder
->dev
;
1158 if (nv_encoder
->crtc
) {
1159 nvd0_crtc_prepare(nv_encoder
->crtc
);
1161 push
= evo_wait(nvd0_mast(dev
), 4);
1163 evo_mthd(push
, 0x0180 + (nv_encoder
->or * 0x20), 1);
1164 evo_data(push
, 0x00000000);
1165 evo_mthd(push
, 0x0080, 1);
1166 evo_data(push
, 0x00000000);
1167 evo_kick(push
, nvd0_mast(dev
));
1170 nv_encoder
->crtc
= NULL
;
1174 static enum drm_connector_status
1175 nvd0_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
1177 struct nvd0_disp
*disp
= nvd0_disp(encoder
->dev
);
1178 int ret
, or = nouveau_encoder(encoder
)->or;
1181 ret
= nv_exec(disp
->core
, NV50_DISP_DAC_LOAD
+ or, &load
, sizeof(load
));
1182 if (ret
|| load
!= 7)
1183 return connector_status_disconnected
;
1185 return connector_status_connected
;
1189 nvd0_dac_destroy(struct drm_encoder
*encoder
)
1191 drm_encoder_cleanup(encoder
);
1195 static const struct drm_encoder_helper_funcs nvd0_dac_hfunc
= {
1196 .dpms
= nvd0_dac_dpms
,
1197 .mode_fixup
= nvd0_dac_mode_fixup
,
1198 .prepare
= nvd0_dac_disconnect
,
1199 .commit
= nvd0_dac_commit
,
1200 .mode_set
= nvd0_dac_mode_set
,
1201 .disable
= nvd0_dac_disconnect
,
1202 .get_crtc
= nvd0_display_crtc_get
,
1203 .detect
= nvd0_dac_detect
1206 static const struct drm_encoder_funcs nvd0_dac_func
= {
1207 .destroy
= nvd0_dac_destroy
,
1211 nvd0_dac_create(struct drm_connector
*connector
, struct dcb_output
*dcbe
)
1213 struct drm_device
*dev
= connector
->dev
;
1214 struct nouveau_encoder
*nv_encoder
;
1215 struct drm_encoder
*encoder
;
1217 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
1220 nv_encoder
->dcb
= dcbe
;
1221 nv_encoder
->or = ffs(dcbe
->or) - 1;
1223 encoder
= to_drm_encoder(nv_encoder
);
1224 encoder
->possible_crtcs
= dcbe
->heads
;
1225 encoder
->possible_clones
= 0;
1226 drm_encoder_init(dev
, encoder
, &nvd0_dac_func
, DRM_MODE_ENCODER_DAC
);
1227 drm_encoder_helper_add(encoder
, &nvd0_dac_hfunc
);
1229 drm_mode_connector_attach_encoder(connector
, encoder
);
1233 /******************************************************************************
1235 *****************************************************************************/
1237 nvd0_audio_mode_set(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
)
1239 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1240 struct nouveau_connector
*nv_connector
;
1241 struct drm_device
*dev
= encoder
->dev
;
1242 struct nouveau_device
*device
= nouveau_dev(dev
);
1243 int i
, or = nv_encoder
->or * 0x30;
1245 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
1246 if (!drm_detect_monitor_audio(nv_connector
->edid
))
1249 nv_mask(device
, 0x10ec10 + or, 0x80000003, 0x80000001);
1251 drm_edid_to_eld(&nv_connector
->base
, nv_connector
->edid
);
1252 if (nv_connector
->base
.eld
[0]) {
1253 u8
*eld
= nv_connector
->base
.eld
;
1255 for (i
= 0; i
< eld
[2] * 4; i
++)
1256 nv_wr32(device
, 0x10ec00 + or, (i
<< 8) | eld
[i
]);
1257 for (i
= eld
[2] * 4; i
< 0x60; i
++)
1258 nv_wr32(device
, 0x10ec00 + or, (i
<< 8) | 0x00);
1260 nv_mask(device
, 0x10ec10 + or, 0x80000002, 0x80000002);
1265 nvd0_audio_disconnect(struct drm_encoder
*encoder
)
1267 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1268 struct drm_device
*dev
= encoder
->dev
;
1269 struct nouveau_device
*device
= nouveau_dev(dev
);
1270 int or = nv_encoder
->or * 0x30;
1272 nv_mask(device
, 0x10ec10 + or, 0x80000003, 0x80000000);
1275 /******************************************************************************
1277 *****************************************************************************/
1279 nvd0_hdmi_mode_set(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
)
1281 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1282 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
1283 struct nouveau_connector
*nv_connector
;
1284 struct drm_device
*dev
= encoder
->dev
;
1285 struct nouveau_device
*device
= nouveau_dev(dev
);
1286 int head
= nv_crtc
->index
* 0x800;
1287 u32 rekey
= 56; /* binary driver, and tegra constant */
1290 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
1291 if (!drm_detect_hdmi_monitor(nv_connector
->edid
))
1294 max_ac_packet
= mode
->htotal
- mode
->hdisplay
;
1295 max_ac_packet
-= rekey
;
1296 max_ac_packet
-= 18; /* constant from tegra */
1297 max_ac_packet
/= 32;
1300 nv_mask(device
, 0x616714 + head
, 0x00000001, 0x00000000);
1301 nv_wr32(device
, 0x61671c + head
, 0x000d0282);
1302 nv_wr32(device
, 0x616720 + head
, 0x0000006f);
1303 nv_wr32(device
, 0x616724 + head
, 0x00000000);
1304 nv_wr32(device
, 0x616728 + head
, 0x00000000);
1305 nv_wr32(device
, 0x61672c + head
, 0x00000000);
1306 nv_mask(device
, 0x616714 + head
, 0x00000001, 0x00000001);
1308 /* ??? InfoFrame? */
1309 nv_mask(device
, 0x6167a4 + head
, 0x00000001, 0x00000000);
1310 nv_wr32(device
, 0x6167ac + head
, 0x00000010);
1311 nv_mask(device
, 0x6167a4 + head
, 0x00000001, 0x00000001);
1314 nv_mask(device
, 0x616798 + head
, 0x401f007f, 0x40000000 | rekey
|
1315 max_ac_packet
<< 16);
1317 /* NFI, audio doesn't work without it though.. */
1318 nv_mask(device
, 0x616548 + head
, 0x00000070, 0x00000000);
1320 nvd0_audio_mode_set(encoder
, mode
);
1324 nvd0_hdmi_disconnect(struct drm_encoder
*encoder
)
1326 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1327 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(nv_encoder
->crtc
);
1328 struct drm_device
*dev
= encoder
->dev
;
1329 struct nouveau_device
*device
= nouveau_dev(dev
);
1330 int head
= nv_crtc
->index
* 0x800;
1332 nvd0_audio_disconnect(encoder
);
1334 nv_mask(device
, 0x616798 + head
, 0x40000000, 0x00000000);
1335 nv_mask(device
, 0x6167a4 + head
, 0x00000001, 0x00000000);
1336 nv_mask(device
, 0x616714 + head
, 0x00000001, 0x00000000);
1339 /******************************************************************************
1341 *****************************************************************************/
1343 nvd0_sor_dp_train_set(struct drm_device
*dev
, struct dcb_output
*dcb
, u8 pattern
)
1345 struct nvd0_disp
*disp
= nvd0_disp(dev
);
1346 const u32
or = ffs(dcb
->or) - 1, link
= !(dcb
->sorconf
.link
& 1);
1347 const u32 moff
= (link
<< 2) | or;
1348 nv_call(disp
->core
, NV94_DISP_SOR_DP_TRAIN
+ moff
, pattern
);
1352 nvd0_sor_dp_train_adj(struct drm_device
*dev
, struct dcb_output
*dcb
,
1353 u8 lane
, u8 swing
, u8 preem
)
1355 struct nvd0_disp
*disp
= nvd0_disp(dev
);
1356 const u32
or = ffs(dcb
->or) - 1, link
= !(dcb
->sorconf
.link
& 1);
1357 const u32 moff
= (link
<< 2) | or;
1358 const u32 data
= (swing
<< 8) | preem
;
1359 nv_call(disp
->core
, NV94_DISP_SOR_DP_DRVCTL(lane
) + moff
, data
);
1363 nvd0_sor_dp_link_set(struct drm_device
*dev
, struct dcb_output
*dcb
, int crtc
,
1364 int link_nr
, u32 link_bw
, bool enhframe
)
1366 struct nvd0_disp
*disp
= nvd0_disp(dev
);
1367 const u32
or = ffs(dcb
->or) - 1, link
= !(dcb
->sorconf
.link
& 1);
1368 const u32 moff
= (crtc
<< 3) | (link
<< 2) | or;
1369 u32 data
= ((link_bw
/ 27000) << 8) | link_nr
;
1371 data
|= NV94_DISP_SOR_DP_LNKCTL_FRAME_ENH
;
1372 nv_call(disp
->core
, NV94_DISP_SOR_DP_LNKCTL
+ moff
, data
);
1376 nvd0_sor_dp_link_get(struct drm_device
*dev
, struct dcb_output
*dcb
,
1377 u32
*link_nr
, u32
*link_bw
)
1379 struct nouveau_device
*device
= nouveau_dev(dev
);
1380 const u32
or = ffs(dcb
->or) - 1, link
= !(dcb
->sorconf
.link
& 1);
1381 const u32 loff
= (or * 0x800) + (link
* 0x80);
1382 const u32 soff
= (or * 0x800);
1383 u32 dpctrl
= nv_rd32(device
, 0x61c10c + loff
) & 0x000f0000;
1384 u32 clksor
= nv_rd32(device
, 0x612300 + soff
);
1386 if (dpctrl
> 0x00030000) *link_nr
= 4;
1387 else if (dpctrl
> 0x00010000) *link_nr
= 2;
1390 *link_bw
= (clksor
& 0x007c0000) >> 18;
1395 nvd0_sor_dp_calc_tu(struct drm_device
*dev
, struct dcb_output
*dcb
,
1396 u32 crtc
, u32 datarate
)
1398 struct nouveau_device
*device
= nouveau_dev(dev
);
1399 const u32 symbol
= 100000;
1401 u32 link_nr
, link_bw
;
1404 nvd0_sor_dp_link_get(dev
, dcb
, &link_nr
, &link_bw
);
1408 do_div(ratio
, link_nr
* link_bw
);
1410 value
= (symbol
- ratio
) * TU
;
1412 do_div(value
, symbol
);
1413 do_div(value
, symbol
);
1416 value
|= 0x08000000;
1418 nv_wr32(device
, 0x616610 + (crtc
* 0x800), value
);
1422 nvd0_sor_dpms(struct drm_encoder
*encoder
, int mode
)
1424 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1425 struct drm_device
*dev
= encoder
->dev
;
1426 struct nvd0_disp
*disp
= nvd0_disp(dev
);
1427 struct drm_encoder
*partner
;
1428 int or = nv_encoder
->or;
1430 nv_encoder
->last_dpms
= mode
;
1432 list_for_each_entry(partner
, &dev
->mode_config
.encoder_list
, head
) {
1433 struct nouveau_encoder
*nv_partner
= nouveau_encoder(partner
);
1435 if (partner
->encoder_type
!= DRM_MODE_ENCODER_TMDS
)
1438 if (nv_partner
!= nv_encoder
&&
1439 nv_partner
->dcb
->or == nv_encoder
->dcb
->or) {
1440 if (nv_partner
->last_dpms
== DRM_MODE_DPMS_ON
)
1446 nv_call(disp
->core
, NV50_DISP_SOR_PWR
+ or, (mode
== DRM_MODE_DPMS_ON
));
1448 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
1449 struct dp_train_func func
= {
1450 .link_set
= nvd0_sor_dp_link_set
,
1451 .train_set
= nvd0_sor_dp_train_set
,
1452 .train_adj
= nvd0_sor_dp_train_adj
1455 nouveau_dp_dpms(encoder
, mode
, nv_encoder
->dp
.datarate
, &func
);
1460 nvd0_sor_mode_fixup(struct drm_encoder
*encoder
,
1461 const struct drm_display_mode
*mode
,
1462 struct drm_display_mode
*adjusted_mode
)
1464 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1465 struct nouveau_connector
*nv_connector
;
1467 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
1468 if (nv_connector
&& nv_connector
->native_mode
) {
1469 if (nv_connector
->scaling_mode
!= DRM_MODE_SCALE_NONE
) {
1470 int id
= adjusted_mode
->base
.id
;
1471 *adjusted_mode
= *nv_connector
->native_mode
;
1472 adjusted_mode
->base
.id
= id
;
1480 nvd0_sor_disconnect(struct drm_encoder
*encoder
)
1482 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1483 struct drm_device
*dev
= encoder
->dev
;
1486 if (nv_encoder
->crtc
) {
1487 nvd0_crtc_prepare(nv_encoder
->crtc
);
1489 push
= evo_wait(nvd0_mast(dev
), 4);
1491 evo_mthd(push
, 0x0200 + (nv_encoder
->or * 0x20), 1);
1492 evo_data(push
, 0x00000000);
1493 evo_mthd(push
, 0x0080, 1);
1494 evo_data(push
, 0x00000000);
1495 evo_kick(push
, nvd0_mast(dev
));
1498 nvd0_hdmi_disconnect(encoder
);
1500 nv_encoder
->crtc
= NULL
;
1501 nv_encoder
->last_dpms
= DRM_MODE_DPMS_OFF
;
1506 nvd0_sor_prepare(struct drm_encoder
*encoder
)
1508 nvd0_sor_disconnect(encoder
);
1509 if (nouveau_encoder(encoder
)->dcb
->type
== DCB_OUTPUT_DP
)
1510 evo_sync(encoder
->dev
);
1514 nvd0_sor_commit(struct drm_encoder
*encoder
)
1519 nvd0_sor_mode_set(struct drm_encoder
*encoder
, struct drm_display_mode
*umode
,
1520 struct drm_display_mode
*mode
)
1522 struct drm_device
*dev
= encoder
->dev
;
1523 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1524 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
1525 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
1526 struct nouveau_connector
*nv_connector
;
1527 struct nvbios
*bios
= &drm
->vbios
;
1528 u32 mode_ctrl
= (1 << nv_crtc
->index
);
1529 u32 syncs
, magic
, *push
;
1533 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
1534 syncs
|= 0x00000008;
1535 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
1536 syncs
|= 0x00000010;
1538 magic
= 0x31ec6000 | (nv_crtc
->index
<< 25);
1539 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
1540 magic
|= 0x00000001;
1542 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
1543 switch (nv_encoder
->dcb
->type
) {
1544 case DCB_OUTPUT_TMDS
:
1545 if (nv_encoder
->dcb
->sorconf
.link
& 1) {
1546 if (mode
->clock
< 165000)
1547 mode_ctrl
|= 0x00000100;
1549 mode_ctrl
|= 0x00000500;
1551 mode_ctrl
|= 0x00000200;
1554 or_config
= (mode_ctrl
& 0x00000f00) >> 8;
1555 if (mode
->clock
>= 165000)
1556 or_config
|= 0x0100;
1558 nvd0_hdmi_mode_set(encoder
, mode
);
1560 case DCB_OUTPUT_LVDS
:
1561 or_config
= (mode_ctrl
& 0x00000f00) >> 8;
1562 if (bios
->fp_no_ddc
) {
1563 if (bios
->fp
.dual_link
)
1564 or_config
|= 0x0100;
1565 if (bios
->fp
.if_is_24bit
)
1566 or_config
|= 0x0200;
1568 if (nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
) {
1569 if (((u8
*)nv_connector
->edid
)[121] == 2)
1570 or_config
|= 0x0100;
1572 if (mode
->clock
>= bios
->fp
.duallink_transition_clk
) {
1573 or_config
|= 0x0100;
1576 if (or_config
& 0x0100) {
1577 if (bios
->fp
.strapless_is_24bit
& 2)
1578 or_config
|= 0x0200;
1580 if (bios
->fp
.strapless_is_24bit
& 1)
1581 or_config
|= 0x0200;
1584 if (nv_connector
->base
.display_info
.bpc
== 8)
1585 or_config
|= 0x0200;
1590 if (nv_connector
->base
.display_info
.bpc
== 6) {
1591 nv_encoder
->dp
.datarate
= mode
->clock
* 18 / 8;
1592 syncs
|= 0x00000002 << 6;
1594 nv_encoder
->dp
.datarate
= mode
->clock
* 24 / 8;
1595 syncs
|= 0x00000005 << 6;
1598 if (nv_encoder
->dcb
->sorconf
.link
& 1)
1599 mode_ctrl
|= 0x00000800;
1601 mode_ctrl
|= 0x00000900;
1603 or_config
= (mode_ctrl
& 0x00000f00) >> 8;
1610 nvd0_sor_dpms(encoder
, DRM_MODE_DPMS_ON
);
1612 if (nv_encoder
->dcb
->type
== DCB_OUTPUT_DP
) {
1613 nvd0_sor_dp_calc_tu(dev
, nv_encoder
->dcb
, nv_crtc
->index
,
1614 nv_encoder
->dp
.datarate
);
1617 push
= evo_wait(nvd0_mast(dev
), 8);
1619 evo_mthd(push
, 0x0404 + (nv_crtc
->index
* 0x300), 2);
1620 evo_data(push
, syncs
);
1621 evo_data(push
, magic
);
1622 evo_mthd(push
, 0x0200 + (nv_encoder
->or * 0x020), 2);
1623 evo_data(push
, mode_ctrl
);
1624 evo_data(push
, or_config
);
1625 evo_kick(push
, nvd0_mast(dev
));
1628 nv_encoder
->crtc
= encoder
->crtc
;
1632 nvd0_sor_destroy(struct drm_encoder
*encoder
)
1634 drm_encoder_cleanup(encoder
);
1638 static const struct drm_encoder_helper_funcs nvd0_sor_hfunc
= {
1639 .dpms
= nvd0_sor_dpms
,
1640 .mode_fixup
= nvd0_sor_mode_fixup
,
1641 .prepare
= nvd0_sor_prepare
,
1642 .commit
= nvd0_sor_commit
,
1643 .mode_set
= nvd0_sor_mode_set
,
1644 .disable
= nvd0_sor_disconnect
,
1645 .get_crtc
= nvd0_display_crtc_get
,
1648 static const struct drm_encoder_funcs nvd0_sor_func
= {
1649 .destroy
= nvd0_sor_destroy
,
1653 nvd0_sor_create(struct drm_connector
*connector
, struct dcb_output
*dcbe
)
1655 struct drm_device
*dev
= connector
->dev
;
1656 struct nouveau_encoder
*nv_encoder
;
1657 struct drm_encoder
*encoder
;
1659 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
1662 nv_encoder
->dcb
= dcbe
;
1663 nv_encoder
->or = ffs(dcbe
->or) - 1;
1664 nv_encoder
->last_dpms
= DRM_MODE_DPMS_OFF
;
1666 encoder
= to_drm_encoder(nv_encoder
);
1667 encoder
->possible_crtcs
= dcbe
->heads
;
1668 encoder
->possible_clones
= 0;
1669 drm_encoder_init(dev
, encoder
, &nvd0_sor_func
, DRM_MODE_ENCODER_TMDS
);
1670 drm_encoder_helper_add(encoder
, &nvd0_sor_hfunc
);
1672 drm_mode_connector_attach_encoder(connector
, encoder
);
1676 /******************************************************************************
1678 *****************************************************************************/
1680 nvd0_display_fini(struct drm_device
*dev
)
1685 nvd0_display_init(struct drm_device
*dev
)
1687 u32
*push
= evo_wait(nvd0_mast(dev
), 32);
1689 evo_mthd(push
, 0x0088, 1);
1690 evo_data(push
, NvEvoSync
);
1691 evo_mthd(push
, 0x0084, 1);
1692 evo_data(push
, 0x00000000);
1693 evo_mthd(push
, 0x0084, 1);
1694 evo_data(push
, 0x80000000);
1695 evo_mthd(push
, 0x008c, 1);
1696 evo_data(push
, 0x00000000);
1697 evo_kick(push
, nvd0_mast(dev
));
1705 nvd0_display_destroy(struct drm_device
*dev
)
1707 struct nvd0_disp
*disp
= nvd0_disp(dev
);
1709 nvd0_dmac_destroy(disp
->core
, &disp
->mast
.base
);
1711 nouveau_bo_unmap(disp
->sync
);
1712 nouveau_bo_ref(NULL
, &disp
->sync
);
1714 nouveau_display(dev
)->priv
= NULL
;
1719 nvd0_display_create(struct drm_device
*dev
)
1721 static const u16 oclass
[] = {
1725 struct nouveau_device
*device
= nouveau_dev(dev
);
1726 struct nouveau_drm
*drm
= nouveau_drm(dev
);
1727 struct dcb_table
*dcb
= &drm
->vbios
.dcb
;
1728 struct drm_connector
*connector
, *tmp
;
1729 struct nvd0_disp
*disp
;
1730 struct dcb_output
*dcbe
;
1733 disp
= kzalloc(sizeof(*disp
), GFP_KERNEL
);
1737 nouveau_display(dev
)->priv
= disp
;
1738 nouveau_display(dev
)->dtor
= nvd0_display_destroy
;
1739 nouveau_display(dev
)->init
= nvd0_display_init
;
1740 nouveau_display(dev
)->fini
= nvd0_display_fini
;
1742 /* small shared memory area we use for notifiers and semaphores */
1743 ret
= nouveau_bo_new(dev
, 4096, 0x1000, TTM_PL_FLAG_VRAM
,
1744 0, 0x0000, NULL
, &disp
->sync
);
1746 ret
= nouveau_bo_pin(disp
->sync
, TTM_PL_FLAG_VRAM
);
1748 ret
= nouveau_bo_map(disp
->sync
);
1750 nouveau_bo_ref(NULL
, &disp
->sync
);
1756 /* attempt to allocate a supported evo display class */
1758 for (i
= 0; ret
&& i
< ARRAY_SIZE(oclass
); i
++) {
1759 ret
= nouveau_object_new(nv_object(drm
), NVDRM_DEVICE
,
1760 0xd1500000, oclass
[i
], NULL
, 0,
1767 /* allocate master evo channel */
1768 ret
= nvd0_dmac_create(disp
->core
, NV50_DISP_MAST_CLASS
, 0,
1769 &(struct nv50_display_mast_class
) {
1770 .pushbuf
= EVO_PUSH_HANDLE(MAST
, 0),
1771 }, sizeof(struct nv50_display_mast_class
),
1772 disp
->sync
->bo
.offset
, &disp
->mast
.base
);
1776 /* create crtc objects to represent the hw heads */
1777 crtcs
= nv_rd32(device
, 0x022448);
1778 for (i
= 0; i
< crtcs
; i
++) {
1779 ret
= nvd0_crtc_create(dev
, disp
->core
, i
);
1784 /* create encoder/connector objects based on VBIOS DCB table */
1785 for (i
= 0, dcbe
= &dcb
->entry
[0]; i
< dcb
->entries
; i
++, dcbe
++) {
1786 connector
= nouveau_connector_create(dev
, dcbe
->connector
);
1787 if (IS_ERR(connector
))
1790 if (dcbe
->location
!= DCB_LOC_ON_CHIP
) {
1791 NV_WARN(drm
, "skipping off-chip encoder %d/%d\n",
1792 dcbe
->type
, ffs(dcbe
->or) - 1);
1796 switch (dcbe
->type
) {
1797 case DCB_OUTPUT_TMDS
:
1798 case DCB_OUTPUT_LVDS
:
1800 nvd0_sor_create(connector
, dcbe
);
1802 case DCB_OUTPUT_ANALOG
:
1803 nvd0_dac_create(connector
, dcbe
);
1806 NV_WARN(drm
, "skipping unsupported encoder %d/%d\n",
1807 dcbe
->type
, ffs(dcbe
->or) - 1);
1812 /* cull any connectors we created that don't have an encoder */
1813 list_for_each_entry_safe(connector
, tmp
, &dev
->mode_config
.connector_list
, head
) {
1814 if (connector
->encoder_ids
[0])
1817 NV_WARN(drm
, "%s has no encoders, removing\n",
1818 drm_get_connector_name(connector
));
1819 connector
->funcs
->destroy(connector
);
1824 nvd0_display_destroy(dev
);