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>
26 #include <linux/hdmi.h>
29 #include <drm/drm_atomic.h>
30 #include <drm/drm_atomic_helper.h>
31 #include <drm/drm_crtc_helper.h>
32 #include <drm/drm_dp_helper.h>
33 #include <drm/drm_fb_helper.h>
34 #include <drm/drm_plane_helper.h>
35 #include <drm/drm_edid.h>
37 #include <nvif/class.h>
38 #include <nvif/cl0002.h>
39 #include <nvif/cl5070.h>
40 #include <nvif/cl507a.h>
41 #include <nvif/cl507b.h>
42 #include <nvif/cl507c.h>
43 #include <nvif/cl507d.h>
44 #include <nvif/cl507e.h>
45 #include <nvif/event.h>
47 #include "nouveau_drv.h"
48 #include "nouveau_dma.h"
49 #include "nouveau_gem.h"
50 #include "nouveau_connector.h"
51 #include "nouveau_encoder.h"
52 #include "nouveau_crtc.h"
53 #include "nouveau_fence.h"
54 #include "nouveau_fbcon.h"
55 #include "nv50_display.h"
59 #define EVO_MASTER (0x00)
60 #define EVO_FLIP(c) (0x01 + (c))
61 #define EVO_OVLY(c) (0x05 + (c))
62 #define EVO_OIMM(c) (0x09 + (c))
63 #define EVO_CURS(c) (0x0d + (c))
65 /* offsets in shared sync bo of various structures */
66 #define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
67 #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
68 #define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
69 #define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
70 #define EVO_FLIP_NTFY0(c) EVO_SYNC((c) + 1, 0x20)
71 #define EVO_FLIP_NTFY1(c) EVO_SYNC((c) + 1, 0x30)
73 /******************************************************************************
75 *****************************************************************************/
76 #define nv50_atom(p) container_of((p), struct nv50_atom, state)
79 struct drm_atomic_state state
;
81 struct list_head outp
;
86 struct nv50_outp_atom
{
87 struct list_head head
;
89 struct drm_encoder
*encoder
;
107 #define nv50_head_atom(p) container_of((p), struct nv50_head_atom, state)
109 struct nv50_head_atom
{
110 struct drm_crtc_state state
;
119 struct nv50_head_mode
{
220 static inline struct nv50_head_atom
*
221 nv50_head_atom_get(struct drm_atomic_state
*state
, struct drm_crtc
*crtc
)
223 struct drm_crtc_state
*statec
= drm_atomic_get_crtc_state(state
, crtc
);
225 return (void *)statec
;
226 return nv50_head_atom(statec
);
229 #define nv50_wndw_atom(p) container_of((p), struct nv50_wndw_atom, state)
231 struct nv50_wndw_atom
{
232 struct drm_plane_state state
;
235 struct drm_rect clip
;
296 /******************************************************************************
298 *****************************************************************************/
301 struct nvif_object user
;
302 struct nvif_device
*device
;
306 nv50_chan_create(struct nvif_device
*device
, struct nvif_object
*disp
,
307 const s32
*oclass
, u8 head
, void *data
, u32 size
,
308 struct nv50_chan
*chan
)
310 struct nvif_sclass
*sclass
;
313 chan
->device
= device
;
315 ret
= n
= nvif_object_sclass_get(disp
, &sclass
);
320 for (i
= 0; i
< n
; i
++) {
321 if (sclass
[i
].oclass
== oclass
[0]) {
322 ret
= nvif_object_init(disp
, 0, oclass
[0],
323 data
, size
, &chan
->user
);
325 nvif_object_map(&chan
->user
, NULL
, 0);
326 nvif_object_sclass_put(&sclass
);
333 nvif_object_sclass_put(&sclass
);
338 nv50_chan_destroy(struct nv50_chan
*chan
)
340 nvif_object_fini(&chan
->user
);
343 /******************************************************************************
345 *****************************************************************************/
348 struct nv50_chan base
;
352 nv50_pioc_destroy(struct nv50_pioc
*pioc
)
354 nv50_chan_destroy(&pioc
->base
);
358 nv50_pioc_create(struct nvif_device
*device
, struct nvif_object
*disp
,
359 const s32
*oclass
, u8 head
, void *data
, u32 size
,
360 struct nv50_pioc
*pioc
)
362 return nv50_chan_create(device
, disp
, oclass
, head
, data
, size
,
366 /******************************************************************************
368 *****************************************************************************/
371 struct nv50_pioc base
;
375 nv50_oimm_create(struct nvif_device
*device
, struct nvif_object
*disp
,
376 int head
, struct nv50_oimm
*oimm
)
378 struct nv50_disp_cursor_v0 args
= {
381 static const s32 oclass
[] = {
390 return nv50_pioc_create(device
, disp
, oclass
, head
, &args
, sizeof(args
),
394 /******************************************************************************
396 *****************************************************************************/
398 struct nv50_dmac_ctxdma
{
399 struct list_head head
;
400 struct nvif_object object
;
404 struct nv50_chan base
;
408 struct nvif_object sync
;
409 struct nvif_object vram
;
410 struct list_head ctxdma
;
412 /* Protects against concurrent pushbuf access to this channel, lock is
413 * grabbed by evo_wait (if the pushbuf reservation is successful) and
414 * dropped again by evo_kick. */
419 nv50_dmac_ctxdma_del(struct nv50_dmac_ctxdma
*ctxdma
)
421 nvif_object_fini(&ctxdma
->object
);
422 list_del(&ctxdma
->head
);
426 static struct nv50_dmac_ctxdma
*
427 nv50_dmac_ctxdma_new(struct nv50_dmac
*dmac
, struct nouveau_framebuffer
*fb
)
429 struct nouveau_drm
*drm
= nouveau_drm(fb
->base
.dev
);
430 struct nv50_dmac_ctxdma
*ctxdma
;
431 const u8 kind
= fb
->nvbo
->kind
;
432 const u32 handle
= 0xfb000000 | kind
;
434 struct nv_dma_v0 base
;
436 struct nv50_dma_v0 nv50
;
437 struct gf100_dma_v0 gf100
;
438 struct gf119_dma_v0 gf119
;
441 u32 argc
= sizeof(args
.base
);
444 list_for_each_entry(ctxdma
, &dmac
->ctxdma
, head
) {
445 if (ctxdma
->object
.handle
== handle
)
449 if (!(ctxdma
= kzalloc(sizeof(*ctxdma
), GFP_KERNEL
)))
450 return ERR_PTR(-ENOMEM
);
451 list_add(&ctxdma
->head
, &dmac
->ctxdma
);
453 args
.base
.target
= NV_DMA_V0_TARGET_VRAM
;
454 args
.base
.access
= NV_DMA_V0_ACCESS_RDWR
;
456 args
.base
.limit
= drm
->client
.device
.info
.ram_user
- 1;
458 if (drm
->client
.device
.info
.chipset
< 0x80) {
459 args
.nv50
.part
= NV50_DMA_V0_PART_256
;
460 argc
+= sizeof(args
.nv50
);
462 if (drm
->client
.device
.info
.chipset
< 0xc0) {
463 args
.nv50
.part
= NV50_DMA_V0_PART_256
;
464 args
.nv50
.kind
= kind
;
465 argc
+= sizeof(args
.nv50
);
467 if (drm
->client
.device
.info
.chipset
< 0xd0) {
468 args
.gf100
.kind
= kind
;
469 argc
+= sizeof(args
.gf100
);
471 args
.gf119
.page
= GF119_DMA_V0_PAGE_LP
;
472 args
.gf119
.kind
= kind
;
473 argc
+= sizeof(args
.gf119
);
476 ret
= nvif_object_init(&dmac
->base
.user
, handle
, NV_DMA_IN_MEMORY
,
477 &args
, argc
, &ctxdma
->object
);
479 nv50_dmac_ctxdma_del(ctxdma
);
487 nv50_dmac_destroy(struct nv50_dmac
*dmac
, struct nvif_object
*disp
)
489 struct nvif_device
*device
= dmac
->base
.device
;
490 struct nv50_dmac_ctxdma
*ctxdma
, *ctxtmp
;
492 list_for_each_entry_safe(ctxdma
, ctxtmp
, &dmac
->ctxdma
, head
) {
493 nv50_dmac_ctxdma_del(ctxdma
);
496 nvif_object_fini(&dmac
->vram
);
497 nvif_object_fini(&dmac
->sync
);
499 nv50_chan_destroy(&dmac
->base
);
502 struct device
*dev
= nvxx_device(device
)->dev
;
503 dma_free_coherent(dev
, PAGE_SIZE
, dmac
->ptr
, dmac
->handle
);
508 nv50_dmac_create(struct nvif_device
*device
, struct nvif_object
*disp
,
509 const s32
*oclass
, u8 head
, void *data
, u32 size
, u64 syncbuf
,
510 struct nv50_dmac
*dmac
)
512 struct nv50_disp_core_channel_dma_v0
*args
= data
;
513 struct nvif_object pushbuf
;
516 mutex_init(&dmac
->lock
);
517 INIT_LIST_HEAD(&dmac
->ctxdma
);
519 dmac
->ptr
= dma_alloc_coherent(nvxx_device(device
)->dev
, PAGE_SIZE
,
520 &dmac
->handle
, GFP_KERNEL
);
524 ret
= nvif_object_init(&device
->object
, 0, NV_DMA_FROM_MEMORY
,
525 &(struct nv_dma_v0
) {
526 .target
= NV_DMA_V0_TARGET_PCI_US
,
527 .access
= NV_DMA_V0_ACCESS_RD
,
528 .start
= dmac
->handle
+ 0x0000,
529 .limit
= dmac
->handle
+ 0x0fff,
530 }, sizeof(struct nv_dma_v0
), &pushbuf
);
534 args
->pushbuf
= nvif_handle(&pushbuf
);
536 ret
= nv50_chan_create(device
, disp
, oclass
, head
, data
, size
,
538 nvif_object_fini(&pushbuf
);
542 ret
= nvif_object_init(&dmac
->base
.user
, 0xf0000000, NV_DMA_IN_MEMORY
,
543 &(struct nv_dma_v0
) {
544 .target
= NV_DMA_V0_TARGET_VRAM
,
545 .access
= NV_DMA_V0_ACCESS_RDWR
,
546 .start
= syncbuf
+ 0x0000,
547 .limit
= syncbuf
+ 0x0fff,
548 }, sizeof(struct nv_dma_v0
),
553 ret
= nvif_object_init(&dmac
->base
.user
, 0xf0000001, NV_DMA_IN_MEMORY
,
554 &(struct nv_dma_v0
) {
555 .target
= NV_DMA_V0_TARGET_VRAM
,
556 .access
= NV_DMA_V0_ACCESS_RDWR
,
558 .limit
= device
->info
.ram_user
- 1,
559 }, sizeof(struct nv_dma_v0
),
567 /******************************************************************************
569 *****************************************************************************/
572 struct nv50_dmac base
;
576 nv50_core_create(struct nvif_device
*device
, struct nvif_object
*disp
,
577 u64 syncbuf
, struct nv50_mast
*core
)
579 struct nv50_disp_core_channel_dma_v0 args
= {
580 .pushbuf
= 0xb0007d00,
582 static const s32 oclass
[] = {
583 GP102_DISP_CORE_CHANNEL_DMA
,
584 GP100_DISP_CORE_CHANNEL_DMA
,
585 GM200_DISP_CORE_CHANNEL_DMA
,
586 GM107_DISP_CORE_CHANNEL_DMA
,
587 GK110_DISP_CORE_CHANNEL_DMA
,
588 GK104_DISP_CORE_CHANNEL_DMA
,
589 GF110_DISP_CORE_CHANNEL_DMA
,
590 GT214_DISP_CORE_CHANNEL_DMA
,
591 GT206_DISP_CORE_CHANNEL_DMA
,
592 GT200_DISP_CORE_CHANNEL_DMA
,
593 G82_DISP_CORE_CHANNEL_DMA
,
594 NV50_DISP_CORE_CHANNEL_DMA
,
598 return nv50_dmac_create(device
, disp
, oclass
, 0, &args
, sizeof(args
),
599 syncbuf
, &core
->base
);
602 /******************************************************************************
604 *****************************************************************************/
607 struct nv50_dmac base
;
613 nv50_base_create(struct nvif_device
*device
, struct nvif_object
*disp
,
614 int head
, u64 syncbuf
, struct nv50_sync
*base
)
616 struct nv50_disp_base_channel_dma_v0 args
= {
617 .pushbuf
= 0xb0007c00 | head
,
620 static const s32 oclass
[] = {
621 GK110_DISP_BASE_CHANNEL_DMA
,
622 GK104_DISP_BASE_CHANNEL_DMA
,
623 GF110_DISP_BASE_CHANNEL_DMA
,
624 GT214_DISP_BASE_CHANNEL_DMA
,
625 GT200_DISP_BASE_CHANNEL_DMA
,
626 G82_DISP_BASE_CHANNEL_DMA
,
627 NV50_DISP_BASE_CHANNEL_DMA
,
631 return nv50_dmac_create(device
, disp
, oclass
, head
, &args
, sizeof(args
),
632 syncbuf
, &base
->base
);
635 /******************************************************************************
637 *****************************************************************************/
640 struct nv50_dmac base
;
644 nv50_ovly_create(struct nvif_device
*device
, struct nvif_object
*disp
,
645 int head
, u64 syncbuf
, struct nv50_ovly
*ovly
)
647 struct nv50_disp_overlay_channel_dma_v0 args
= {
648 .pushbuf
= 0xb0007e00 | head
,
651 static const s32 oclass
[] = {
652 GK104_DISP_OVERLAY_CONTROL_DMA
,
653 GF110_DISP_OVERLAY_CONTROL_DMA
,
654 GT214_DISP_OVERLAY_CHANNEL_DMA
,
655 GT200_DISP_OVERLAY_CHANNEL_DMA
,
656 G82_DISP_OVERLAY_CHANNEL_DMA
,
657 NV50_DISP_OVERLAY_CHANNEL_DMA
,
661 return nv50_dmac_create(device
, disp
, oclass
, head
, &args
, sizeof(args
),
662 syncbuf
, &ovly
->base
);
666 struct nouveau_crtc base
;
668 struct nouveau_bo
*nvbo
[2];
671 struct nv50_ovly ovly
;
672 struct nv50_oimm oimm
;
675 #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
676 #define nv50_ovly(c) (&nv50_head(c)->ovly)
677 #define nv50_oimm(c) (&nv50_head(c)->oimm)
678 #define nv50_chan(c) (&(c)->base.base)
679 #define nv50_vers(c) nv50_chan(c)->user.oclass
682 struct nvif_object
*disp
;
683 struct nv50_mast mast
;
685 struct nouveau_bo
*sync
;
690 static struct nv50_disp
*
691 nv50_disp(struct drm_device
*dev
)
693 return nouveau_display(dev
)->priv
;
696 #define nv50_mast(d) (&nv50_disp(d)->mast)
698 /******************************************************************************
699 * EVO channel helpers
700 *****************************************************************************/
702 evo_wait(void *evoc
, int nr
)
704 struct nv50_dmac
*dmac
= evoc
;
705 struct nvif_device
*device
= dmac
->base
.device
;
706 u32 put
= nvif_rd32(&dmac
->base
.user
, 0x0000) / 4;
708 mutex_lock(&dmac
->lock
);
709 if (put
+ nr
>= (PAGE_SIZE
/ 4) - 8) {
710 dmac
->ptr
[put
] = 0x20000000;
712 nvif_wr32(&dmac
->base
.user
, 0x0000, 0x00000000);
713 if (nvif_msec(device
, 2000,
714 if (!nvif_rd32(&dmac
->base
.user
, 0x0004))
717 mutex_unlock(&dmac
->lock
);
718 pr_err("nouveau: evo channel stalled\n");
725 return dmac
->ptr
+ put
;
729 evo_kick(u32
*push
, void *evoc
)
731 struct nv50_dmac
*dmac
= evoc
;
732 nvif_wr32(&dmac
->base
.user
, 0x0000, (push
- dmac
->ptr
) << 2);
733 mutex_unlock(&dmac
->lock
);
736 #define evo_mthd(p, m, s) do { \
737 const u32 _m = (m), _s = (s); \
738 if (drm_debug & DRM_UT_KMS) \
739 pr_err("%04x %d %s\n", _m, _s, __func__); \
740 *((p)++) = ((_s << 18) | _m); \
743 #define evo_data(p, d) do { \
744 const u32 _d = (d); \
745 if (drm_debug & DRM_UT_KMS) \
746 pr_err("\t%08x\n", _d); \
750 /******************************************************************************
752 *****************************************************************************/
753 #define nv50_wndw(p) container_of((p), struct nv50_wndw, plane)
756 const struct nv50_wndw_func
*func
;
757 struct nv50_dmac
*dmac
;
759 struct drm_plane plane
;
761 struct nvif_notify notify
;
767 struct nv50_wndw_func
{
768 void *(*dtor
)(struct nv50_wndw
*);
769 int (*acquire
)(struct nv50_wndw
*, struct nv50_wndw_atom
*asyw
,
770 struct nv50_head_atom
*asyh
);
771 void (*release
)(struct nv50_wndw
*, struct nv50_wndw_atom
*asyw
,
772 struct nv50_head_atom
*asyh
);
773 void (*prepare
)(struct nv50_wndw
*, struct nv50_head_atom
*asyh
,
774 struct nv50_wndw_atom
*asyw
);
776 void (*sema_set
)(struct nv50_wndw
*, struct nv50_wndw_atom
*);
777 void (*sema_clr
)(struct nv50_wndw
*);
778 void (*ntfy_set
)(struct nv50_wndw
*, struct nv50_wndw_atom
*);
779 void (*ntfy_clr
)(struct nv50_wndw
*);
780 int (*ntfy_wait_begun
)(struct nv50_wndw
*, struct nv50_wndw_atom
*);
781 void (*image_set
)(struct nv50_wndw
*, struct nv50_wndw_atom
*);
782 void (*image_clr
)(struct nv50_wndw
*);
783 void (*lut
)(struct nv50_wndw
*, struct nv50_wndw_atom
*);
784 void (*point
)(struct nv50_wndw
*, struct nv50_wndw_atom
*);
786 u32 (*update
)(struct nv50_wndw
*, u32 interlock
);
790 nv50_wndw_wait_armed(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
793 return wndw
->func
->ntfy_wait_begun(wndw
, asyw
);
798 nv50_wndw_flush_clr(struct nv50_wndw
*wndw
, u32 interlock
, bool flush
,
799 struct nv50_wndw_atom
*asyw
)
801 if (asyw
->clr
.sema
&& (!asyw
->set
.sema
|| flush
))
802 wndw
->func
->sema_clr(wndw
);
803 if (asyw
->clr
.ntfy
&& (!asyw
->set
.ntfy
|| flush
))
804 wndw
->func
->ntfy_clr(wndw
);
805 if (asyw
->clr
.image
&& (!asyw
->set
.image
|| flush
))
806 wndw
->func
->image_clr(wndw
);
808 return flush
? wndw
->func
->update(wndw
, interlock
) : 0;
812 nv50_wndw_flush_set(struct nv50_wndw
*wndw
, u32 interlock
,
813 struct nv50_wndw_atom
*asyw
)
816 asyw
->image
.mode
= 0;
817 asyw
->image
.interval
= 1;
820 if (asyw
->set
.sema
) wndw
->func
->sema_set (wndw
, asyw
);
821 if (asyw
->set
.ntfy
) wndw
->func
->ntfy_set (wndw
, asyw
);
822 if (asyw
->set
.image
) wndw
->func
->image_set(wndw
, asyw
);
823 if (asyw
->set
.lut
) wndw
->func
->lut (wndw
, asyw
);
824 if (asyw
->set
.point
) wndw
->func
->point (wndw
, asyw
);
826 return wndw
->func
->update(wndw
, interlock
);
830 nv50_wndw_atomic_check_release(struct nv50_wndw
*wndw
,
831 struct nv50_wndw_atom
*asyw
,
832 struct nv50_head_atom
*asyh
)
834 struct nouveau_drm
*drm
= nouveau_drm(wndw
->plane
.dev
);
835 NV_ATOMIC(drm
, "%s release\n", wndw
->plane
.name
);
836 wndw
->func
->release(wndw
, asyw
, asyh
);
837 asyw
->ntfy
.handle
= 0;
838 asyw
->sema
.handle
= 0;
842 nv50_wndw_atomic_check_acquire(struct nv50_wndw
*wndw
,
843 struct nv50_wndw_atom
*asyw
,
844 struct nv50_head_atom
*asyh
)
846 struct nouveau_framebuffer
*fb
= nouveau_framebuffer(asyw
->state
.fb
);
847 struct nouveau_drm
*drm
= nouveau_drm(wndw
->plane
.dev
);
850 NV_ATOMIC(drm
, "%s acquire\n", wndw
->plane
.name
);
853 asyw
->clip
.x2
= asyh
->state
.mode
.hdisplay
;
854 asyw
->clip
.y2
= asyh
->state
.mode
.vdisplay
;
856 asyw
->image
.w
= fb
->base
.width
;
857 asyw
->image
.h
= fb
->base
.height
;
858 asyw
->image
.kind
= fb
->nvbo
->kind
;
860 if (asyh
->state
.pageflip_flags
& DRM_MODE_PAGE_FLIP_ASYNC
)
865 if (asyw
->image
.kind
) {
866 asyw
->image
.layout
= 0;
867 if (drm
->client
.device
.info
.chipset
>= 0xc0)
868 asyw
->image
.block
= fb
->nvbo
->mode
>> 4;
870 asyw
->image
.block
= fb
->nvbo
->mode
;
871 asyw
->image
.pitch
= (fb
->base
.pitches
[0] / 4) << 4;
873 asyw
->image
.layout
= 1;
874 asyw
->image
.block
= 0;
875 asyw
->image
.pitch
= fb
->base
.pitches
[0];
878 ret
= wndw
->func
->acquire(wndw
, asyw
, asyh
);
882 if (asyw
->set
.image
) {
883 if (!(asyw
->image
.mode
= asyw
->interval
? 0 : 1))
884 asyw
->image
.interval
= asyw
->interval
;
886 asyw
->image
.interval
= 0;
893 nv50_wndw_atomic_check(struct drm_plane
*plane
, struct drm_plane_state
*state
)
895 struct nouveau_drm
*drm
= nouveau_drm(plane
->dev
);
896 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
897 struct nv50_wndw_atom
*armw
= nv50_wndw_atom(wndw
->plane
.state
);
898 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(state
);
899 struct nv50_head_atom
*harm
= NULL
, *asyh
= NULL
;
900 bool varm
= false, asyv
= false, asym
= false;
903 NV_ATOMIC(drm
, "%s atomic_check\n", plane
->name
);
904 if (asyw
->state
.crtc
) {
905 asyh
= nv50_head_atom_get(asyw
->state
.state
, asyw
->state
.crtc
);
907 return PTR_ERR(asyh
);
908 asym
= drm_atomic_crtc_needs_modeset(&asyh
->state
);
909 asyv
= asyh
->state
.active
;
912 if (armw
->state
.crtc
) {
913 harm
= nv50_head_atom_get(asyw
->state
.state
, armw
->state
.crtc
);
915 return PTR_ERR(harm
);
916 varm
= harm
->state
.crtc
->state
->active
;
920 asyw
->point
.x
= asyw
->state
.crtc_x
;
921 asyw
->point
.y
= asyw
->state
.crtc_y
;
922 if (memcmp(&armw
->point
, &asyw
->point
, sizeof(asyw
->point
)))
923 asyw
->set
.point
= true;
925 ret
= nv50_wndw_atomic_check_acquire(wndw
, asyw
, asyh
);
930 nv50_wndw_atomic_check_release(wndw
, asyw
, harm
);
936 asyw
->clr
.ntfy
= armw
->ntfy
.handle
!= 0;
937 asyw
->clr
.sema
= armw
->sema
.handle
!= 0;
938 if (wndw
->func
->image_clr
)
939 asyw
->clr
.image
= armw
->image
.handle
!= 0;
940 asyw
->set
.lut
= wndw
->func
->lut
&& asyv
;
947 nv50_wndw_cleanup_fb(struct drm_plane
*plane
, struct drm_plane_state
*old_state
)
949 struct nouveau_framebuffer
*fb
= nouveau_framebuffer(old_state
->fb
);
950 struct nouveau_drm
*drm
= nouveau_drm(plane
->dev
);
952 NV_ATOMIC(drm
, "%s cleanup: %p\n", plane
->name
, old_state
->fb
);
956 nouveau_bo_unpin(fb
->nvbo
);
960 nv50_wndw_prepare_fb(struct drm_plane
*plane
, struct drm_plane_state
*state
)
962 struct nouveau_framebuffer
*fb
= nouveau_framebuffer(state
->fb
);
963 struct nouveau_drm
*drm
= nouveau_drm(plane
->dev
);
964 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
965 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(state
);
966 struct nv50_head_atom
*asyh
;
967 struct nv50_dmac_ctxdma
*ctxdma
;
970 NV_ATOMIC(drm
, "%s prepare: %p\n", plane
->name
, state
->fb
);
974 ret
= nouveau_bo_pin(fb
->nvbo
, TTM_PL_FLAG_VRAM
, true);
978 ctxdma
= nv50_dmac_ctxdma_new(wndw
->dmac
, fb
);
979 if (IS_ERR(ctxdma
)) {
980 nouveau_bo_unpin(fb
->nvbo
);
981 return PTR_ERR(ctxdma
);
984 asyw
->state
.fence
= reservation_object_get_excl_rcu(fb
->nvbo
->bo
.resv
);
985 asyw
->image
.handle
= ctxdma
->object
.handle
;
986 asyw
->image
.offset
= fb
->nvbo
->bo
.offset
;
988 if (wndw
->func
->prepare
) {
989 asyh
= nv50_head_atom_get(asyw
->state
.state
, asyw
->state
.crtc
);
991 return PTR_ERR(asyh
);
993 wndw
->func
->prepare(wndw
, asyh
, asyw
);
999 static const struct drm_plane_helper_funcs
1000 nv50_wndw_helper
= {
1001 .prepare_fb
= nv50_wndw_prepare_fb
,
1002 .cleanup_fb
= nv50_wndw_cleanup_fb
,
1003 .atomic_check
= nv50_wndw_atomic_check
,
1007 nv50_wndw_atomic_destroy_state(struct drm_plane
*plane
,
1008 struct drm_plane_state
*state
)
1010 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(state
);
1011 __drm_atomic_helper_plane_destroy_state(&asyw
->state
);
1015 static struct drm_plane_state
*
1016 nv50_wndw_atomic_duplicate_state(struct drm_plane
*plane
)
1018 struct nv50_wndw_atom
*armw
= nv50_wndw_atom(plane
->state
);
1019 struct nv50_wndw_atom
*asyw
;
1020 if (!(asyw
= kmalloc(sizeof(*asyw
), GFP_KERNEL
)))
1022 __drm_atomic_helper_plane_duplicate_state(plane
, &asyw
->state
);
1024 asyw
->sema
= armw
->sema
;
1025 asyw
->ntfy
= armw
->ntfy
;
1026 asyw
->image
= armw
->image
;
1027 asyw
->point
= armw
->point
;
1028 asyw
->lut
= armw
->lut
;
1031 return &asyw
->state
;
1035 nv50_wndw_reset(struct drm_plane
*plane
)
1037 struct nv50_wndw_atom
*asyw
;
1039 if (WARN_ON(!(asyw
= kzalloc(sizeof(*asyw
), GFP_KERNEL
))))
1043 plane
->funcs
->atomic_destroy_state(plane
, plane
->state
);
1044 plane
->state
= &asyw
->state
;
1045 plane
->state
->plane
= plane
;
1046 plane
->state
->rotation
= DRM_MODE_ROTATE_0
;
1050 nv50_wndw_destroy(struct drm_plane
*plane
)
1052 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
1054 nvif_notify_fini(&wndw
->notify
);
1055 data
= wndw
->func
->dtor(wndw
);
1056 drm_plane_cleanup(&wndw
->plane
);
1060 static const struct drm_plane_funcs
1062 .update_plane
= drm_atomic_helper_update_plane
,
1063 .disable_plane
= drm_atomic_helper_disable_plane
,
1064 .destroy
= nv50_wndw_destroy
,
1065 .reset
= nv50_wndw_reset
,
1066 .atomic_duplicate_state
= nv50_wndw_atomic_duplicate_state
,
1067 .atomic_destroy_state
= nv50_wndw_atomic_destroy_state
,
1071 nv50_wndw_fini(struct nv50_wndw
*wndw
)
1073 nvif_notify_put(&wndw
->notify
);
1077 nv50_wndw_init(struct nv50_wndw
*wndw
)
1079 nvif_notify_get(&wndw
->notify
);
1083 nv50_wndw_ctor(const struct nv50_wndw_func
*func
, struct drm_device
*dev
,
1084 enum drm_plane_type type
, const char *name
, int index
,
1085 struct nv50_dmac
*dmac
, const u32
*format
, int nformat
,
1086 struct nv50_wndw
*wndw
)
1093 ret
= drm_universal_plane_init(dev
, &wndw
->plane
, 0, &nv50_wndw
,
1094 format
, nformat
, NULL
,
1095 type
, "%s-%d", name
, index
);
1099 drm_plane_helper_add(&wndw
->plane
, &nv50_wndw_helper
);
1103 /******************************************************************************
1105 *****************************************************************************/
1106 #define nv50_curs(p) container_of((p), struct nv50_curs, wndw)
1109 struct nv50_wndw wndw
;
1110 struct nvif_object chan
;
1114 nv50_curs_update(struct nv50_wndw
*wndw
, u32 interlock
)
1116 struct nv50_curs
*curs
= nv50_curs(wndw
);
1117 nvif_wr32(&curs
->chan
, 0x0080, 0x00000000);
1122 nv50_curs_point(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
1124 struct nv50_curs
*curs
= nv50_curs(wndw
);
1125 nvif_wr32(&curs
->chan
, 0x0084, (asyw
->point
.y
<< 16) | asyw
->point
.x
);
1129 nv50_curs_prepare(struct nv50_wndw
*wndw
, struct nv50_head_atom
*asyh
,
1130 struct nv50_wndw_atom
*asyw
)
1132 u32 handle
= nv50_disp(wndw
->plane
.dev
)->mast
.base
.vram
.handle
;
1133 u32 offset
= asyw
->image
.offset
;
1134 if (asyh
->curs
.handle
!= handle
|| asyh
->curs
.offset
!= offset
) {
1135 asyh
->curs
.handle
= handle
;
1136 asyh
->curs
.offset
= offset
;
1137 asyh
->set
.curs
= asyh
->curs
.visible
;
1142 nv50_curs_release(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
,
1143 struct nv50_head_atom
*asyh
)
1145 asyh
->curs
.visible
= false;
1149 nv50_curs_acquire(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
,
1150 struct nv50_head_atom
*asyh
)
1154 ret
= drm_atomic_helper_check_plane_state(&asyw
->state
, &asyh
->state
,
1156 DRM_PLANE_HELPER_NO_SCALING
,
1157 DRM_PLANE_HELPER_NO_SCALING
,
1159 asyh
->curs
.visible
= asyw
->state
.visible
;
1160 if (ret
|| !asyh
->curs
.visible
)
1163 switch (asyw
->state
.fb
->width
) {
1164 case 32: asyh
->curs
.layout
= 0; break;
1165 case 64: asyh
->curs
.layout
= 1; break;
1170 if (asyw
->state
.fb
->width
!= asyw
->state
.fb
->height
)
1173 switch (asyw
->state
.fb
->format
->format
) {
1174 case DRM_FORMAT_ARGB8888
: asyh
->curs
.format
= 1; break;
1184 nv50_curs_dtor(struct nv50_wndw
*wndw
)
1186 struct nv50_curs
*curs
= nv50_curs(wndw
);
1187 nvif_object_fini(&curs
->chan
);
1192 nv50_curs_format
[] = {
1193 DRM_FORMAT_ARGB8888
,
1196 static const struct nv50_wndw_func
1198 .dtor
= nv50_curs_dtor
,
1199 .acquire
= nv50_curs_acquire
,
1200 .release
= nv50_curs_release
,
1201 .prepare
= nv50_curs_prepare
,
1202 .point
= nv50_curs_point
,
1203 .update
= nv50_curs_update
,
1207 nv50_curs_new(struct nouveau_drm
*drm
, struct nv50_head
*head
,
1208 struct nv50_curs
**pcurs
)
1210 static const struct nvif_mclass curses
[] = {
1211 { GK104_DISP_CURSOR
, 0 },
1212 { GF110_DISP_CURSOR
, 0 },
1213 { GT214_DISP_CURSOR
, 0 },
1214 { G82_DISP_CURSOR
, 0 },
1215 { NV50_DISP_CURSOR
, 0 },
1218 struct nv50_disp_cursor_v0 args
= {
1219 .head
= head
->base
.index
,
1221 struct nv50_disp
*disp
= nv50_disp(drm
->dev
);
1222 struct nv50_curs
*curs
;
1225 cid
= nvif_mclass(disp
->disp
, curses
);
1227 NV_ERROR(drm
, "No supported cursor immediate class\n");
1231 if (!(curs
= *pcurs
= kzalloc(sizeof(*curs
), GFP_KERNEL
)))
1234 ret
= nv50_wndw_ctor(&nv50_curs
, drm
->dev
, DRM_PLANE_TYPE_CURSOR
,
1235 "curs", head
->base
.index
, &disp
->mast
.base
,
1236 nv50_curs_format
, ARRAY_SIZE(nv50_curs_format
),
1243 ret
= nvif_object_init(disp
->disp
, 0, curses
[cid
].oclass
, &args
,
1244 sizeof(args
), &curs
->chan
);
1246 NV_ERROR(drm
, "curs%04x allocation failed: %d\n",
1247 curses
[cid
].oclass
, ret
);
1254 /******************************************************************************
1256 *****************************************************************************/
1257 #define nv50_base(p) container_of((p), struct nv50_base, wndw)
1260 struct nv50_wndw wndw
;
1261 struct nv50_sync chan
;
1266 nv50_base_notify(struct nvif_notify
*notify
)
1268 return NVIF_NOTIFY_KEEP
;
1272 nv50_base_lut(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
1274 struct nv50_base
*base
= nv50_base(wndw
);
1276 if ((push
= evo_wait(&base
->chan
, 2))) {
1277 evo_mthd(push
, 0x00e0, 1);
1278 evo_data(push
, asyw
->lut
.enable
<< 30);
1279 evo_kick(push
, &base
->chan
);
1284 nv50_base_image_clr(struct nv50_wndw
*wndw
)
1286 struct nv50_base
*base
= nv50_base(wndw
);
1288 if ((push
= evo_wait(&base
->chan
, 4))) {
1289 evo_mthd(push
, 0x0084, 1);
1290 evo_data(push
, 0x00000000);
1291 evo_mthd(push
, 0x00c0, 1);
1292 evo_data(push
, 0x00000000);
1293 evo_kick(push
, &base
->chan
);
1298 nv50_base_image_set(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
1300 struct nv50_base
*base
= nv50_base(wndw
);
1301 const s32 oclass
= base
->chan
.base
.base
.user
.oclass
;
1303 if ((push
= evo_wait(&base
->chan
, 10))) {
1304 evo_mthd(push
, 0x0084, 1);
1305 evo_data(push
, (asyw
->image
.mode
<< 8) |
1306 (asyw
->image
.interval
<< 4));
1307 evo_mthd(push
, 0x00c0, 1);
1308 evo_data(push
, asyw
->image
.handle
);
1309 if (oclass
< G82_DISP_BASE_CHANNEL_DMA
) {
1310 evo_mthd(push
, 0x0800, 5);
1311 evo_data(push
, asyw
->image
.offset
>> 8);
1312 evo_data(push
, 0x00000000);
1313 evo_data(push
, (asyw
->image
.h
<< 16) | asyw
->image
.w
);
1314 evo_data(push
, (asyw
->image
.layout
<< 20) |
1317 evo_data(push
, (asyw
->image
.kind
<< 16) |
1318 (asyw
->image
.format
<< 8));
1320 if (oclass
< GF110_DISP_BASE_CHANNEL_DMA
) {
1321 evo_mthd(push
, 0x0800, 5);
1322 evo_data(push
, asyw
->image
.offset
>> 8);
1323 evo_data(push
, 0x00000000);
1324 evo_data(push
, (asyw
->image
.h
<< 16) | asyw
->image
.w
);
1325 evo_data(push
, (asyw
->image
.layout
<< 20) |
1328 evo_data(push
, asyw
->image
.format
<< 8);
1330 evo_mthd(push
, 0x0400, 5);
1331 evo_data(push
, asyw
->image
.offset
>> 8);
1332 evo_data(push
, 0x00000000);
1333 evo_data(push
, (asyw
->image
.h
<< 16) | asyw
->image
.w
);
1334 evo_data(push
, (asyw
->image
.layout
<< 24) |
1337 evo_data(push
, asyw
->image
.format
<< 8);
1339 evo_kick(push
, &base
->chan
);
1344 nv50_base_ntfy_clr(struct nv50_wndw
*wndw
)
1346 struct nv50_base
*base
= nv50_base(wndw
);
1348 if ((push
= evo_wait(&base
->chan
, 2))) {
1349 evo_mthd(push
, 0x00a4, 1);
1350 evo_data(push
, 0x00000000);
1351 evo_kick(push
, &base
->chan
);
1356 nv50_base_ntfy_set(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
1358 struct nv50_base
*base
= nv50_base(wndw
);
1360 if ((push
= evo_wait(&base
->chan
, 3))) {
1361 evo_mthd(push
, 0x00a0, 2);
1362 evo_data(push
, (asyw
->ntfy
.awaken
<< 30) | asyw
->ntfy
.offset
);
1363 evo_data(push
, asyw
->ntfy
.handle
);
1364 evo_kick(push
, &base
->chan
);
1369 nv50_base_sema_clr(struct nv50_wndw
*wndw
)
1371 struct nv50_base
*base
= nv50_base(wndw
);
1373 if ((push
= evo_wait(&base
->chan
, 2))) {
1374 evo_mthd(push
, 0x0094, 1);
1375 evo_data(push
, 0x00000000);
1376 evo_kick(push
, &base
->chan
);
1381 nv50_base_sema_set(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
1383 struct nv50_base
*base
= nv50_base(wndw
);
1385 if ((push
= evo_wait(&base
->chan
, 5))) {
1386 evo_mthd(push
, 0x0088, 4);
1387 evo_data(push
, asyw
->sema
.offset
);
1388 evo_data(push
, asyw
->sema
.acquire
);
1389 evo_data(push
, asyw
->sema
.release
);
1390 evo_data(push
, asyw
->sema
.handle
);
1391 evo_kick(push
, &base
->chan
);
1396 nv50_base_update(struct nv50_wndw
*wndw
, u32 interlock
)
1398 struct nv50_base
*base
= nv50_base(wndw
);
1401 if (!(push
= evo_wait(&base
->chan
, 2)))
1403 evo_mthd(push
, 0x0080, 1);
1404 evo_data(push
, interlock
);
1405 evo_kick(push
, &base
->chan
);
1407 if (base
->chan
.base
.base
.user
.oclass
< GF110_DISP_BASE_CHANNEL_DMA
)
1408 return interlock
? 2 << (base
->id
* 8) : 0;
1409 return interlock
? 2 << (base
->id
* 4) : 0;
1413 nv50_base_ntfy_wait_begun(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
)
1415 struct nouveau_drm
*drm
= nouveau_drm(wndw
->plane
.dev
);
1416 struct nv50_disp
*disp
= nv50_disp(wndw
->plane
.dev
);
1417 if (nvif_msec(&drm
->client
.device
, 2000ULL,
1418 u32 data
= nouveau_bo_rd32(disp
->sync
, asyw
->ntfy
.offset
/ 4);
1419 if ((data
& 0xc0000000) == 0x40000000)
1428 nv50_base_release(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
,
1429 struct nv50_head_atom
*asyh
)
1435 nv50_base_acquire(struct nv50_wndw
*wndw
, struct nv50_wndw_atom
*asyw
,
1436 struct nv50_head_atom
*asyh
)
1438 const struct drm_framebuffer
*fb
= asyw
->state
.fb
;
1441 if (!fb
->format
->depth
)
1444 ret
= drm_atomic_helper_check_plane_state(&asyw
->state
, &asyh
->state
,
1446 DRM_PLANE_HELPER_NO_SCALING
,
1447 DRM_PLANE_HELPER_NO_SCALING
,
1452 asyh
->base
.depth
= fb
->format
->depth
;
1453 asyh
->base
.cpp
= fb
->format
->cpp
[0];
1454 asyh
->base
.x
= asyw
->state
.src
.x1
>> 16;
1455 asyh
->base
.y
= asyw
->state
.src
.y1
>> 16;
1456 asyh
->base
.w
= asyw
->state
.fb
->width
;
1457 asyh
->base
.h
= asyw
->state
.fb
->height
;
1459 switch (fb
->format
->format
) {
1460 case DRM_FORMAT_C8
: asyw
->image
.format
= 0x1e; break;
1461 case DRM_FORMAT_RGB565
: asyw
->image
.format
= 0xe8; break;
1462 case DRM_FORMAT_XRGB1555
:
1463 case DRM_FORMAT_ARGB1555
: asyw
->image
.format
= 0xe9; break;
1464 case DRM_FORMAT_XRGB8888
:
1465 case DRM_FORMAT_ARGB8888
: asyw
->image
.format
= 0xcf; break;
1466 case DRM_FORMAT_XBGR2101010
:
1467 case DRM_FORMAT_ABGR2101010
: asyw
->image
.format
= 0xd1; break;
1468 case DRM_FORMAT_XBGR8888
:
1469 case DRM_FORMAT_ABGR8888
: asyw
->image
.format
= 0xd5; break;
1475 asyw
->lut
.enable
= 1;
1476 asyw
->set
.image
= true;
1481 nv50_base_dtor(struct nv50_wndw
*wndw
)
1483 struct nv50_disp
*disp
= nv50_disp(wndw
->plane
.dev
);
1484 struct nv50_base
*base
= nv50_base(wndw
);
1485 nv50_dmac_destroy(&base
->chan
.base
, disp
->disp
);
1490 nv50_base_format
[] = {
1493 DRM_FORMAT_XRGB1555
,
1494 DRM_FORMAT_ARGB1555
,
1495 DRM_FORMAT_XRGB8888
,
1496 DRM_FORMAT_ARGB8888
,
1497 DRM_FORMAT_XBGR2101010
,
1498 DRM_FORMAT_ABGR2101010
,
1499 DRM_FORMAT_XBGR8888
,
1500 DRM_FORMAT_ABGR8888
,
1503 static const struct nv50_wndw_func
1505 .dtor
= nv50_base_dtor
,
1506 .acquire
= nv50_base_acquire
,
1507 .release
= nv50_base_release
,
1508 .sema_set
= nv50_base_sema_set
,
1509 .sema_clr
= nv50_base_sema_clr
,
1510 .ntfy_set
= nv50_base_ntfy_set
,
1511 .ntfy_clr
= nv50_base_ntfy_clr
,
1512 .ntfy_wait_begun
= nv50_base_ntfy_wait_begun
,
1513 .image_set
= nv50_base_image_set
,
1514 .image_clr
= nv50_base_image_clr
,
1515 .lut
= nv50_base_lut
,
1516 .update
= nv50_base_update
,
1520 nv50_base_new(struct nouveau_drm
*drm
, struct nv50_head
*head
,
1521 struct nv50_base
**pbase
)
1523 struct nv50_disp
*disp
= nv50_disp(drm
->dev
);
1524 struct nv50_base
*base
;
1527 if (!(base
= *pbase
= kzalloc(sizeof(*base
), GFP_KERNEL
)))
1529 base
->id
= head
->base
.index
;
1530 base
->wndw
.ntfy
= EVO_FLIP_NTFY0(base
->id
);
1531 base
->wndw
.sema
= EVO_FLIP_SEM0(base
->id
);
1532 base
->wndw
.data
= 0x00000000;
1534 ret
= nv50_wndw_ctor(&nv50_base
, drm
->dev
, DRM_PLANE_TYPE_PRIMARY
,
1535 "base", base
->id
, &base
->chan
.base
,
1536 nv50_base_format
, ARRAY_SIZE(nv50_base_format
),
1543 ret
= nv50_base_create(&drm
->client
.device
, disp
->disp
, base
->id
,
1544 disp
->sync
->bo
.offset
, &base
->chan
);
1548 return nvif_notify_init(&base
->chan
.base
.base
.user
, nv50_base_notify
,
1550 NV50_DISP_BASE_CHANNEL_DMA_V0_NTFY_UEVENT
,
1551 &(struct nvif_notify_uevent_req
) {},
1552 sizeof(struct nvif_notify_uevent_req
),
1553 sizeof(struct nvif_notify_uevent_rep
),
1554 &base
->wndw
.notify
);
1557 /******************************************************************************
1559 *****************************************************************************/
1561 nv50_head_procamp(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1563 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1565 if ((push
= evo_wait(core
, 2))) {
1566 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
)
1567 evo_mthd(push
, 0x08a8 + (head
->base
.index
* 0x400), 1);
1569 evo_mthd(push
, 0x0498 + (head
->base
.index
* 0x300), 1);
1570 evo_data(push
, (asyh
->procamp
.sat
.sin
<< 20) |
1571 (asyh
->procamp
.sat
.cos
<< 8));
1572 evo_kick(push
, core
);
1577 nv50_head_dither(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1579 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1581 if ((push
= evo_wait(core
, 2))) {
1582 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
)
1583 evo_mthd(push
, 0x08a0 + (head
->base
.index
* 0x0400), 1);
1585 if (core
->base
.user
.oclass
< GK104_DISP_CORE_CHANNEL_DMA
)
1586 evo_mthd(push
, 0x0490 + (head
->base
.index
* 0x0300), 1);
1588 evo_mthd(push
, 0x04a0 + (head
->base
.index
* 0x0300), 1);
1589 evo_data(push
, (asyh
->dither
.mode
<< 3) |
1590 (asyh
->dither
.bits
<< 1) |
1591 asyh
->dither
.enable
);
1592 evo_kick(push
, core
);
1597 nv50_head_ovly(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1599 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1603 if (asyh
->base
.cpp
) {
1604 switch (asyh
->base
.cpp
) {
1605 case 8: bounds
|= 0x00000500; break;
1606 case 4: bounds
|= 0x00000300; break;
1607 case 2: bounds
|= 0x00000100; break;
1612 bounds
|= 0x00000001;
1615 if ((push
= evo_wait(core
, 2))) {
1616 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
)
1617 evo_mthd(push
, 0x0904 + head
->base
.index
* 0x400, 1);
1619 evo_mthd(push
, 0x04d4 + head
->base
.index
* 0x300, 1);
1620 evo_data(push
, bounds
);
1621 evo_kick(push
, core
);
1626 nv50_head_base(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1628 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1632 if (asyh
->base
.cpp
) {
1633 switch (asyh
->base
.cpp
) {
1634 case 8: bounds
|= 0x00000500; break;
1635 case 4: bounds
|= 0x00000300; break;
1636 case 2: bounds
|= 0x00000100; break;
1637 case 1: bounds
|= 0x00000000; break;
1642 bounds
|= 0x00000001;
1645 if ((push
= evo_wait(core
, 2))) {
1646 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
)
1647 evo_mthd(push
, 0x0900 + head
->base
.index
* 0x400, 1);
1649 evo_mthd(push
, 0x04d0 + head
->base
.index
* 0x300, 1);
1650 evo_data(push
, bounds
);
1651 evo_kick(push
, core
);
1656 nv50_head_curs_clr(struct nv50_head
*head
)
1658 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1660 if ((push
= evo_wait(core
, 4))) {
1661 if (core
->base
.user
.oclass
< G82_DISP_CORE_CHANNEL_DMA
) {
1662 evo_mthd(push
, 0x0880 + head
->base
.index
* 0x400, 1);
1663 evo_data(push
, 0x05000000);
1665 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
1666 evo_mthd(push
, 0x0880 + head
->base
.index
* 0x400, 1);
1667 evo_data(push
, 0x05000000);
1668 evo_mthd(push
, 0x089c + head
->base
.index
* 0x400, 1);
1669 evo_data(push
, 0x00000000);
1671 evo_mthd(push
, 0x0480 + head
->base
.index
* 0x300, 1);
1672 evo_data(push
, 0x05000000);
1673 evo_mthd(push
, 0x048c + head
->base
.index
* 0x300, 1);
1674 evo_data(push
, 0x00000000);
1676 evo_kick(push
, core
);
1681 nv50_head_curs_set(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1683 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1685 if ((push
= evo_wait(core
, 5))) {
1686 if (core
->base
.user
.oclass
< G82_DISP_BASE_CHANNEL_DMA
) {
1687 evo_mthd(push
, 0x0880 + head
->base
.index
* 0x400, 2);
1688 evo_data(push
, 0x80000000 | (asyh
->curs
.layout
<< 26) |
1689 (asyh
->curs
.format
<< 24));
1690 evo_data(push
, asyh
->curs
.offset
>> 8);
1692 if (core
->base
.user
.oclass
< GF110_DISP_BASE_CHANNEL_DMA
) {
1693 evo_mthd(push
, 0x0880 + head
->base
.index
* 0x400, 2);
1694 evo_data(push
, 0x80000000 | (asyh
->curs
.layout
<< 26) |
1695 (asyh
->curs
.format
<< 24));
1696 evo_data(push
, asyh
->curs
.offset
>> 8);
1697 evo_mthd(push
, 0x089c + head
->base
.index
* 0x400, 1);
1698 evo_data(push
, asyh
->curs
.handle
);
1700 evo_mthd(push
, 0x0480 + head
->base
.index
* 0x300, 2);
1701 evo_data(push
, 0x80000000 | (asyh
->curs
.layout
<< 26) |
1702 (asyh
->curs
.format
<< 24));
1703 evo_data(push
, asyh
->curs
.offset
>> 8);
1704 evo_mthd(push
, 0x048c + head
->base
.index
* 0x300, 1);
1705 evo_data(push
, asyh
->curs
.handle
);
1707 evo_kick(push
, core
);
1712 nv50_head_core_clr(struct nv50_head
*head
)
1714 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1716 if ((push
= evo_wait(core
, 2))) {
1717 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
)
1718 evo_mthd(push
, 0x0874 + head
->base
.index
* 0x400, 1);
1720 evo_mthd(push
, 0x0474 + head
->base
.index
* 0x300, 1);
1721 evo_data(push
, 0x00000000);
1722 evo_kick(push
, core
);
1727 nv50_head_core_set(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1729 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1731 if ((push
= evo_wait(core
, 9))) {
1732 if (core
->base
.user
.oclass
< G82_DISP_CORE_CHANNEL_DMA
) {
1733 evo_mthd(push
, 0x0860 + head
->base
.index
* 0x400, 1);
1734 evo_data(push
, asyh
->core
.offset
>> 8);
1735 evo_mthd(push
, 0x0868 + head
->base
.index
* 0x400, 4);
1736 evo_data(push
, (asyh
->core
.h
<< 16) | asyh
->core
.w
);
1737 evo_data(push
, asyh
->core
.layout
<< 20 |
1738 (asyh
->core
.pitch
>> 8) << 8 |
1740 evo_data(push
, asyh
->core
.kind
<< 16 |
1741 asyh
->core
.format
<< 8);
1742 evo_data(push
, asyh
->core
.handle
);
1743 evo_mthd(push
, 0x08c0 + head
->base
.index
* 0x400, 1);
1744 evo_data(push
, (asyh
->core
.y
<< 16) | asyh
->core
.x
);
1745 /* EVO will complain with INVALID_STATE if we have an
1746 * active cursor and (re)specify HeadSetContextDmaIso
1747 * without also updating HeadSetOffsetCursor.
1749 asyh
->set
.curs
= asyh
->curs
.visible
;
1751 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
1752 evo_mthd(push
, 0x0860 + head
->base
.index
* 0x400, 1);
1753 evo_data(push
, asyh
->core
.offset
>> 8);
1754 evo_mthd(push
, 0x0868 + head
->base
.index
* 0x400, 4);
1755 evo_data(push
, (asyh
->core
.h
<< 16) | asyh
->core
.w
);
1756 evo_data(push
, asyh
->core
.layout
<< 20 |
1757 (asyh
->core
.pitch
>> 8) << 8 |
1759 evo_data(push
, asyh
->core
.format
<< 8);
1760 evo_data(push
, asyh
->core
.handle
);
1761 evo_mthd(push
, 0x08c0 + head
->base
.index
* 0x400, 1);
1762 evo_data(push
, (asyh
->core
.y
<< 16) | asyh
->core
.x
);
1764 evo_mthd(push
, 0x0460 + head
->base
.index
* 0x300, 1);
1765 evo_data(push
, asyh
->core
.offset
>> 8);
1766 evo_mthd(push
, 0x0468 + head
->base
.index
* 0x300, 4);
1767 evo_data(push
, (asyh
->core
.h
<< 16) | asyh
->core
.w
);
1768 evo_data(push
, asyh
->core
.layout
<< 24 |
1769 (asyh
->core
.pitch
>> 8) << 8 |
1771 evo_data(push
, asyh
->core
.format
<< 8);
1772 evo_data(push
, asyh
->core
.handle
);
1773 evo_mthd(push
, 0x04b0 + head
->base
.index
* 0x300, 1);
1774 evo_data(push
, (asyh
->core
.y
<< 16) | asyh
->core
.x
);
1776 evo_kick(push
, core
);
1781 nv50_head_lut_clr(struct nv50_head
*head
)
1783 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1785 if ((push
= evo_wait(core
, 4))) {
1786 if (core
->base
.user
.oclass
< G82_DISP_CORE_CHANNEL_DMA
) {
1787 evo_mthd(push
, 0x0840 + (head
->base
.index
* 0x400), 1);
1788 evo_data(push
, 0x40000000);
1790 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
1791 evo_mthd(push
, 0x0840 + (head
->base
.index
* 0x400), 1);
1792 evo_data(push
, 0x40000000);
1793 evo_mthd(push
, 0x085c + (head
->base
.index
* 0x400), 1);
1794 evo_data(push
, 0x00000000);
1796 evo_mthd(push
, 0x0440 + (head
->base
.index
* 0x300), 1);
1797 evo_data(push
, 0x03000000);
1798 evo_mthd(push
, 0x045c + (head
->base
.index
* 0x300), 1);
1799 evo_data(push
, 0x00000000);
1801 evo_kick(push
, core
);
1806 nv50_head_lut_load(struct drm_property_blob
*blob
, int mode
,
1807 struct nouveau_bo
*nvbo
)
1809 struct drm_color_lut
*in
= (struct drm_color_lut
*)blob
->data
;
1810 void __iomem
*lut
= (u8
*)nvbo_kmap_obj_iovirtual(nvbo
);
1811 const int size
= blob
->length
/ sizeof(*in
);
1815 /* This can't happen.. But it shuts the compiler up. */
1816 if (WARN_ON(size
!= 256))
1820 case 0: /* LORES. */
1821 case 1: /* HIRES. */
1826 case 7: /* INTERPOLATE_257_UNITY_RANGE. */
1836 for (i
= 0; i
< size
; i
++) {
1837 r
= (drm_color_lut_extract(in
[i
]. red
, bits
) + zero
) << shift
;
1838 g
= (drm_color_lut_extract(in
[i
].green
, bits
) + zero
) << shift
;
1839 b
= (drm_color_lut_extract(in
[i
]. blue
, bits
) + zero
) << shift
;
1840 writew(r
, lut
+ (i
* 0x08) + 0);
1841 writew(g
, lut
+ (i
* 0x08) + 2);
1842 writew(b
, lut
+ (i
* 0x08) + 4);
1845 /* INTERPOLATE modes require a "next" entry to interpolate with,
1846 * so we replicate the last entry to deal with this for now.
1848 writew(r
, lut
+ (i
* 0x08) + 0);
1849 writew(g
, lut
+ (i
* 0x08) + 2);
1850 writew(b
, lut
+ (i
* 0x08) + 4);
1854 nv50_head_lut_set(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1856 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1858 if ((push
= evo_wait(core
, 7))) {
1859 if (core
->base
.user
.oclass
< G82_DISP_CORE_CHANNEL_DMA
) {
1860 evo_mthd(push
, 0x0840 + (head
->base
.index
* 0x400), 2);
1861 evo_data(push
, 0x80000000 | asyh
->lut
.mode
<< 30);
1862 evo_data(push
, asyh
->lut
.offset
>> 8);
1864 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
1865 evo_mthd(push
, 0x0840 + (head
->base
.index
* 0x400), 2);
1866 evo_data(push
, 0x80000000 | asyh
->lut
.mode
<< 30);
1867 evo_data(push
, asyh
->lut
.offset
>> 8);
1868 evo_mthd(push
, 0x085c + (head
->base
.index
* 0x400), 1);
1869 evo_data(push
, asyh
->lut
.handle
);
1871 evo_mthd(push
, 0x0440 + (head
->base
.index
* 0x300), 4);
1872 evo_data(push
, 0x80000000 | asyh
->lut
.mode
<< 24);
1873 evo_data(push
, asyh
->lut
.offset
>> 8);
1874 evo_data(push
, 0x00000000);
1875 evo_data(push
, 0x00000000);
1876 evo_mthd(push
, 0x045c + (head
->base
.index
* 0x300), 1);
1877 evo_data(push
, asyh
->lut
.handle
);
1879 evo_kick(push
, core
);
1884 nv50_head_mode(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1886 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1887 struct nv50_head_mode
*m
= &asyh
->mode
;
1889 if ((push
= evo_wait(core
, 14))) {
1890 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
1891 evo_mthd(push
, 0x0804 + (head
->base
.index
* 0x400), 2);
1892 evo_data(push
, 0x00800000 | m
->clock
);
1893 evo_data(push
, m
->interlace
? 0x00000002 : 0x00000000);
1894 evo_mthd(push
, 0x0810 + (head
->base
.index
* 0x400), 7);
1895 evo_data(push
, 0x00000000);
1896 evo_data(push
, (m
->v
.active
<< 16) | m
->h
.active
);
1897 evo_data(push
, (m
->v
.synce
<< 16) | m
->h
.synce
);
1898 evo_data(push
, (m
->v
.blanke
<< 16) | m
->h
.blanke
);
1899 evo_data(push
, (m
->v
.blanks
<< 16) | m
->h
.blanks
);
1900 evo_data(push
, (m
->v
.blank2e
<< 16) | m
->v
.blank2s
);
1901 evo_data(push
, asyh
->mode
.v
.blankus
);
1902 evo_mthd(push
, 0x082c + (head
->base
.index
* 0x400), 1);
1903 evo_data(push
, 0x00000000);
1905 evo_mthd(push
, 0x0410 + (head
->base
.index
* 0x300), 6);
1906 evo_data(push
, 0x00000000);
1907 evo_data(push
, (m
->v
.active
<< 16) | m
->h
.active
);
1908 evo_data(push
, (m
->v
.synce
<< 16) | m
->h
.synce
);
1909 evo_data(push
, (m
->v
.blanke
<< 16) | m
->h
.blanke
);
1910 evo_data(push
, (m
->v
.blanks
<< 16) | m
->h
.blanks
);
1911 evo_data(push
, (m
->v
.blank2e
<< 16) | m
->v
.blank2s
);
1912 evo_mthd(push
, 0x042c + (head
->base
.index
* 0x300), 2);
1913 evo_data(push
, 0x00000000); /* ??? */
1914 evo_data(push
, 0xffffff00);
1915 evo_mthd(push
, 0x0450 + (head
->base
.index
* 0x300), 3);
1916 evo_data(push
, m
->clock
* 1000);
1917 evo_data(push
, 0x00200000); /* ??? */
1918 evo_data(push
, m
->clock
* 1000);
1920 evo_kick(push
, core
);
1925 nv50_head_view(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1927 struct nv50_dmac
*core
= &nv50_disp(head
->base
.base
.dev
)->mast
.base
;
1929 if ((push
= evo_wait(core
, 10))) {
1930 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
1931 evo_mthd(push
, 0x08a4 + (head
->base
.index
* 0x400), 1);
1932 evo_data(push
, 0x00000000);
1933 evo_mthd(push
, 0x08c8 + (head
->base
.index
* 0x400), 1);
1934 evo_data(push
, (asyh
->view
.iH
<< 16) | asyh
->view
.iW
);
1935 evo_mthd(push
, 0x08d8 + (head
->base
.index
* 0x400), 2);
1936 evo_data(push
, (asyh
->view
.oH
<< 16) | asyh
->view
.oW
);
1937 evo_data(push
, (asyh
->view
.oH
<< 16) | asyh
->view
.oW
);
1939 evo_mthd(push
, 0x0494 + (head
->base
.index
* 0x300), 1);
1940 evo_data(push
, 0x00000000);
1941 evo_mthd(push
, 0x04b8 + (head
->base
.index
* 0x300), 1);
1942 evo_data(push
, (asyh
->view
.iH
<< 16) | asyh
->view
.iW
);
1943 evo_mthd(push
, 0x04c0 + (head
->base
.index
* 0x300), 3);
1944 evo_data(push
, (asyh
->view
.oH
<< 16) | asyh
->view
.oW
);
1945 evo_data(push
, (asyh
->view
.oH
<< 16) | asyh
->view
.oW
);
1946 evo_data(push
, (asyh
->view
.oH
<< 16) | asyh
->view
.oW
);
1948 evo_kick(push
, core
);
1953 nv50_head_flush_clr(struct nv50_head
*head
, struct nv50_head_atom
*asyh
, bool y
)
1955 if (asyh
->clr
.ilut
&& (!asyh
->set
.ilut
|| y
))
1956 nv50_head_lut_clr(head
);
1957 if (asyh
->clr
.core
&& (!asyh
->set
.core
|| y
))
1958 nv50_head_core_clr(head
);
1959 if (asyh
->clr
.curs
&& (!asyh
->set
.curs
|| y
))
1960 nv50_head_curs_clr(head
);
1964 nv50_head_flush_set(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
1966 if (asyh
->set
.view
) nv50_head_view (head
, asyh
);
1967 if (asyh
->set
.mode
) nv50_head_mode (head
, asyh
);
1968 if (asyh
->set
.ilut
) {
1969 struct nouveau_bo
*nvbo
= head
->lut
.nvbo
[head
->lut
.next
];
1970 struct drm_property_blob
*blob
= asyh
->state
.gamma_lut
;
1972 nv50_head_lut_load(blob
, asyh
->lut
.mode
, nvbo
);
1973 asyh
->lut
.offset
= nvbo
->bo
.offset
;
1974 head
->lut
.next
^= 1;
1975 nv50_head_lut_set(head
, asyh
);
1977 if (asyh
->set
.core
) nv50_head_core_set(head
, asyh
);
1978 if (asyh
->set
.curs
) nv50_head_curs_set(head
, asyh
);
1979 if (asyh
->set
.base
) nv50_head_base (head
, asyh
);
1980 if (asyh
->set
.ovly
) nv50_head_ovly (head
, asyh
);
1981 if (asyh
->set
.dither
) nv50_head_dither (head
, asyh
);
1982 if (asyh
->set
.procamp
) nv50_head_procamp (head
, asyh
);
1986 nv50_head_atomic_check_procamp(struct nv50_head_atom
*armh
,
1987 struct nv50_head_atom
*asyh
,
1988 struct nouveau_conn_atom
*asyc
)
1990 const int vib
= asyc
->procamp
.color_vibrance
- 100;
1991 const int hue
= asyc
->procamp
.vibrant_hue
- 90;
1992 const int adj
= (vib
> 0) ? 50 : 0;
1993 asyh
->procamp
.sat
.cos
= ((vib
* 2047 + adj
) / 100) & 0xfff;
1994 asyh
->procamp
.sat
.sin
= ((hue
* 2047) / 100) & 0xfff;
1995 asyh
->set
.procamp
= true;
1999 nv50_head_atomic_check_dither(struct nv50_head_atom
*armh
,
2000 struct nv50_head_atom
*asyh
,
2001 struct nouveau_conn_atom
*asyc
)
2003 struct drm_connector
*connector
= asyc
->state
.connector
;
2006 if (asyc
->dither
.mode
== DITHERING_MODE_AUTO
) {
2007 if (asyh
->base
.depth
> connector
->display_info
.bpc
* 3)
2008 mode
= DITHERING_MODE_DYNAMIC2X2
;
2010 mode
= asyc
->dither
.mode
;
2013 if (asyc
->dither
.depth
== DITHERING_DEPTH_AUTO
) {
2014 if (connector
->display_info
.bpc
>= 8)
2015 mode
|= DITHERING_DEPTH_8BPC
;
2017 mode
|= asyc
->dither
.depth
;
2020 asyh
->dither
.enable
= mode
;
2021 asyh
->dither
.bits
= mode
>> 1;
2022 asyh
->dither
.mode
= mode
>> 3;
2023 asyh
->set
.dither
= true;
2027 nv50_head_atomic_check_view(struct nv50_head_atom
*armh
,
2028 struct nv50_head_atom
*asyh
,
2029 struct nouveau_conn_atom
*asyc
)
2031 struct drm_connector
*connector
= asyc
->state
.connector
;
2032 struct drm_display_mode
*omode
= &asyh
->state
.adjusted_mode
;
2033 struct drm_display_mode
*umode
= &asyh
->state
.mode
;
2034 int mode
= asyc
->scaler
.mode
;
2036 int umode_vdisplay
, omode_hdisplay
, omode_vdisplay
;
2038 if (connector
->edid_blob_ptr
)
2039 edid
= (struct edid
*)connector
->edid_blob_ptr
->data
;
2043 if (!asyc
->scaler
.full
) {
2044 if (mode
== DRM_MODE_SCALE_NONE
)
2047 /* Non-EDID LVDS/eDP mode. */
2048 mode
= DRM_MODE_SCALE_FULLSCREEN
;
2051 /* For the user-specified mode, we must ignore doublescan and
2052 * the like, but honor frame packing.
2054 umode_vdisplay
= umode
->vdisplay
;
2055 if ((umode
->flags
& DRM_MODE_FLAG_3D_MASK
) == DRM_MODE_FLAG_3D_FRAME_PACKING
)
2056 umode_vdisplay
+= umode
->vtotal
;
2057 asyh
->view
.iW
= umode
->hdisplay
;
2058 asyh
->view
.iH
= umode_vdisplay
;
2059 /* For the output mode, we can just use the stock helper. */
2060 drm_mode_get_hv_timing(omode
, &omode_hdisplay
, &omode_vdisplay
);
2061 asyh
->view
.oW
= omode_hdisplay
;
2062 asyh
->view
.oH
= omode_vdisplay
;
2064 /* Add overscan compensation if necessary, will keep the aspect
2065 * ratio the same as the backend mode unless overridden by the
2066 * user setting both hborder and vborder properties.
2068 if ((asyc
->scaler
.underscan
.mode
== UNDERSCAN_ON
||
2069 (asyc
->scaler
.underscan
.mode
== UNDERSCAN_AUTO
&&
2070 drm_detect_hdmi_monitor(edid
)))) {
2071 u32 bX
= asyc
->scaler
.underscan
.hborder
;
2072 u32 bY
= asyc
->scaler
.underscan
.vborder
;
2073 u32 r
= (asyh
->view
.oH
<< 19) / asyh
->view
.oW
;
2076 asyh
->view
.oW
-= (bX
* 2);
2077 if (bY
) asyh
->view
.oH
-= (bY
* 2);
2078 else asyh
->view
.oH
= ((asyh
->view
.oW
* r
) + (r
/ 2)) >> 19;
2080 asyh
->view
.oW
-= (asyh
->view
.oW
>> 4) + 32;
2081 if (bY
) asyh
->view
.oH
-= (bY
* 2);
2082 else asyh
->view
.oH
= ((asyh
->view
.oW
* r
) + (r
/ 2)) >> 19;
2086 /* Handle CENTER/ASPECT scaling, taking into account the areas
2087 * removed already for overscan compensation.
2090 case DRM_MODE_SCALE_CENTER
:
2091 asyh
->view
.oW
= min((u16
)umode
->hdisplay
, asyh
->view
.oW
);
2092 asyh
->view
.oH
= min((u16
)umode_vdisplay
, asyh
->view
.oH
);
2094 case DRM_MODE_SCALE_ASPECT
:
2095 if (asyh
->view
.oH
< asyh
->view
.oW
) {
2096 u32 r
= (asyh
->view
.iW
<< 19) / asyh
->view
.iH
;
2097 asyh
->view
.oW
= ((asyh
->view
.oH
* r
) + (r
/ 2)) >> 19;
2099 u32 r
= (asyh
->view
.iH
<< 19) / asyh
->view
.iW
;
2100 asyh
->view
.oH
= ((asyh
->view
.oW
* r
) + (r
/ 2)) >> 19;
2107 asyh
->set
.view
= true;
2111 nv50_head_atomic_check_lut(struct nv50_head
*head
,
2112 struct nv50_head_atom
*armh
,
2113 struct nv50_head_atom
*asyh
)
2115 struct nv50_disp
*disp
= nv50_disp(head
->base
.base
.dev
);
2117 /* An I8 surface without an input LUT makes no sense, and
2118 * EVO will throw an error if you try.
2120 * Legacy clients actually cause this due to the order in
2121 * which they call ioctls, so we will enable the LUT with
2122 * whatever contents the buffer already contains to avoid
2123 * triggering the error check.
2125 if (!asyh
->state
.gamma_lut
&& asyh
->base
.cpp
!= 1) {
2126 asyh
->lut
.handle
= 0;
2127 asyh
->clr
.ilut
= armh
->lut
.visible
;
2131 if (disp
->disp
->oclass
< GF110_DISP
) {
2132 asyh
->lut
.mode
= (asyh
->base
.cpp
== 1) ? 0 : 1;
2133 asyh
->set
.ilut
= true;
2136 asyh
->set
.ilut
= asyh
->state
.color_mgmt_changed
;
2138 asyh
->lut
.handle
= disp
->mast
.base
.vram
.handle
;
2142 nv50_head_atomic_check_mode(struct nv50_head
*head
, struct nv50_head_atom
*asyh
)
2144 struct drm_display_mode
*mode
= &asyh
->state
.adjusted_mode
;
2145 struct nv50_head_mode
*m
= &asyh
->mode
;
2148 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
| CRTC_STEREO_DOUBLE
);
2151 * DRM modes are defined in terms of a repeating interval
2152 * starting with the active display area. The hardware modes
2153 * are defined in terms of a repeating interval starting one
2154 * unit (pixel or line) into the sync pulse. So, add bias.
2157 m
->h
.active
= mode
->crtc_htotal
;
2158 m
->h
.synce
= mode
->crtc_hsync_end
- mode
->crtc_hsync_start
- 1;
2159 m
->h
.blanke
= mode
->crtc_hblank_end
- mode
->crtc_hsync_start
- 1;
2160 m
->h
.blanks
= m
->h
.blanke
+ mode
->crtc_hdisplay
;
2162 m
->v
.active
= mode
->crtc_vtotal
;
2163 m
->v
.synce
= mode
->crtc_vsync_end
- mode
->crtc_vsync_start
- 1;
2164 m
->v
.blanke
= mode
->crtc_vblank_end
- mode
->crtc_vsync_start
- 1;
2165 m
->v
.blanks
= m
->v
.blanke
+ mode
->crtc_vdisplay
;
2167 /*XXX: Safe underestimate, even "0" works */
2168 blankus
= (m
->v
.active
- mode
->crtc_vdisplay
- 2) * m
->h
.active
;
2170 blankus
/= mode
->crtc_clock
;
2171 m
->v
.blankus
= blankus
;
2173 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
) {
2174 m
->v
.blank2e
= m
->v
.active
+ m
->v
.blanke
;
2175 m
->v
.blank2s
= m
->v
.blank2e
+ mode
->crtc_vdisplay
;
2176 m
->v
.active
= (m
->v
.active
* 2) + 1;
2177 m
->interlace
= true;
2181 m
->interlace
= false;
2183 m
->clock
= mode
->crtc_clock
;
2185 asyh
->set
.mode
= true;
2189 nv50_head_atomic_check(struct drm_crtc
*crtc
, struct drm_crtc_state
*state
)
2191 struct nouveau_drm
*drm
= nouveau_drm(crtc
->dev
);
2192 struct nv50_disp
*disp
= nv50_disp(crtc
->dev
);
2193 struct nv50_head
*head
= nv50_head(crtc
);
2194 struct nv50_head_atom
*armh
= nv50_head_atom(crtc
->state
);
2195 struct nv50_head_atom
*asyh
= nv50_head_atom(state
);
2196 struct nouveau_conn_atom
*asyc
= NULL
;
2197 struct drm_connector_state
*conns
;
2198 struct drm_connector
*conn
;
2201 NV_ATOMIC(drm
, "%s atomic_check %d\n", crtc
->name
, asyh
->state
.active
);
2202 if (asyh
->state
.active
) {
2203 for_each_new_connector_in_state(asyh
->state
.state
, conn
, conns
, i
) {
2204 if (conns
->crtc
== crtc
) {
2205 asyc
= nouveau_conn_atom(conns
);
2210 if (armh
->state
.active
) {
2212 if (asyh
->state
.mode_changed
)
2213 asyc
->set
.scaler
= true;
2214 if (armh
->base
.depth
!= asyh
->base
.depth
)
2215 asyc
->set
.dither
= true;
2219 asyc
->set
.mask
= ~0;
2220 asyh
->set
.mask
= ~0;
2223 if (asyh
->state
.mode_changed
)
2224 nv50_head_atomic_check_mode(head
, asyh
);
2226 if (asyh
->state
.color_mgmt_changed
||
2227 asyh
->base
.cpp
!= armh
->base
.cpp
)
2228 nv50_head_atomic_check_lut(head
, armh
, asyh
);
2229 asyh
->lut
.visible
= asyh
->lut
.handle
!= 0;
2232 if (asyc
->set
.scaler
)
2233 nv50_head_atomic_check_view(armh
, asyh
, asyc
);
2234 if (asyc
->set
.dither
)
2235 nv50_head_atomic_check_dither(armh
, asyh
, asyc
);
2236 if (asyc
->set
.procamp
)
2237 nv50_head_atomic_check_procamp(armh
, asyh
, asyc
);
2240 if ((asyh
->core
.visible
= (asyh
->base
.cpp
!= 0))) {
2241 asyh
->core
.x
= asyh
->base
.x
;
2242 asyh
->core
.y
= asyh
->base
.y
;
2243 asyh
->core
.w
= asyh
->base
.w
;
2244 asyh
->core
.h
= asyh
->base
.h
;
2246 if ((asyh
->core
.visible
= asyh
->curs
.visible
) ||
2247 (asyh
->core
.visible
= asyh
->lut
.visible
)) {
2248 /*XXX: We need to either find some way of having the
2249 * primary base layer appear black, while still
2250 * being able to display the other layers, or we
2251 * need to allocate a dummy black surface here.
2255 asyh
->core
.w
= asyh
->state
.mode
.hdisplay
;
2256 asyh
->core
.h
= asyh
->state
.mode
.vdisplay
;
2258 asyh
->core
.handle
= disp
->mast
.base
.vram
.handle
;
2259 asyh
->core
.offset
= 0;
2260 asyh
->core
.format
= 0xcf;
2261 asyh
->core
.kind
= 0;
2262 asyh
->core
.layout
= 1;
2263 asyh
->core
.block
= 0;
2264 asyh
->core
.pitch
= ALIGN(asyh
->core
.w
, 64) * 4;
2265 asyh
->set
.base
= armh
->base
.cpp
!= asyh
->base
.cpp
;
2266 asyh
->set
.ovly
= armh
->ovly
.cpp
!= asyh
->ovly
.cpp
;
2268 asyh
->lut
.visible
= false;
2269 asyh
->core
.visible
= false;
2270 asyh
->curs
.visible
= false;
2275 if (!drm_atomic_crtc_needs_modeset(&asyh
->state
)) {
2276 if (asyh
->core
.visible
) {
2277 if (memcmp(&armh
->core
, &asyh
->core
, sizeof(asyh
->core
)))
2278 asyh
->set
.core
= true;
2280 if (armh
->core
.visible
) {
2281 asyh
->clr
.core
= true;
2284 if (asyh
->curs
.visible
) {
2285 if (memcmp(&armh
->curs
, &asyh
->curs
, sizeof(asyh
->curs
)))
2286 asyh
->set
.curs
= true;
2288 if (armh
->curs
.visible
) {
2289 asyh
->clr
.curs
= true;
2292 asyh
->clr
.ilut
= armh
->lut
.visible
;
2293 asyh
->clr
.core
= armh
->core
.visible
;
2294 asyh
->clr
.curs
= armh
->curs
.visible
;
2295 asyh
->set
.ilut
= asyh
->lut
.visible
;
2296 asyh
->set
.core
= asyh
->core
.visible
;
2297 asyh
->set
.curs
= asyh
->curs
.visible
;
2300 if (asyh
->clr
.mask
|| asyh
->set
.mask
)
2301 nv50_atom(asyh
->state
.state
)->lock_core
= true;
2305 static const struct drm_crtc_helper_funcs
2307 .atomic_check
= nv50_head_atomic_check
,
2311 nv50_head_atomic_destroy_state(struct drm_crtc
*crtc
,
2312 struct drm_crtc_state
*state
)
2314 struct nv50_head_atom
*asyh
= nv50_head_atom(state
);
2315 __drm_atomic_helper_crtc_destroy_state(&asyh
->state
);
2319 static struct drm_crtc_state
*
2320 nv50_head_atomic_duplicate_state(struct drm_crtc
*crtc
)
2322 struct nv50_head_atom
*armh
= nv50_head_atom(crtc
->state
);
2323 struct nv50_head_atom
*asyh
;
2324 if (!(asyh
= kmalloc(sizeof(*asyh
), GFP_KERNEL
)))
2326 __drm_atomic_helper_crtc_duplicate_state(crtc
, &asyh
->state
);
2327 asyh
->view
= armh
->view
;
2328 asyh
->mode
= armh
->mode
;
2329 asyh
->lut
= armh
->lut
;
2330 asyh
->core
= armh
->core
;
2331 asyh
->curs
= armh
->curs
;
2332 asyh
->base
= armh
->base
;
2333 asyh
->ovly
= armh
->ovly
;
2334 asyh
->dither
= armh
->dither
;
2335 asyh
->procamp
= armh
->procamp
;
2338 return &asyh
->state
;
2342 __drm_atomic_helper_crtc_reset(struct drm_crtc
*crtc
,
2343 struct drm_crtc_state
*state
)
2346 crtc
->funcs
->atomic_destroy_state(crtc
, crtc
->state
);
2347 crtc
->state
= state
;
2348 crtc
->state
->crtc
= crtc
;
2352 nv50_head_reset(struct drm_crtc
*crtc
)
2354 struct nv50_head_atom
*asyh
;
2356 if (WARN_ON(!(asyh
= kzalloc(sizeof(*asyh
), GFP_KERNEL
))))
2359 __drm_atomic_helper_crtc_reset(crtc
, &asyh
->state
);
2363 nv50_head_destroy(struct drm_crtc
*crtc
)
2365 struct nv50_disp
*disp
= nv50_disp(crtc
->dev
);
2366 struct nv50_head
*head
= nv50_head(crtc
);
2369 nv50_dmac_destroy(&head
->ovly
.base
, disp
->disp
);
2370 nv50_pioc_destroy(&head
->oimm
.base
);
2372 for (i
= 0; i
< ARRAY_SIZE(head
->lut
.nvbo
); i
++)
2373 nouveau_bo_unmap_unpin_unref(&head
->lut
.nvbo
[i
]);
2375 drm_crtc_cleanup(crtc
);
2379 static const struct drm_crtc_funcs
2381 .reset
= nv50_head_reset
,
2382 .gamma_set
= drm_atomic_helper_legacy_gamma_set
,
2383 .destroy
= nv50_head_destroy
,
2384 .set_config
= drm_atomic_helper_set_config
,
2385 .page_flip
= drm_atomic_helper_page_flip
,
2386 .atomic_duplicate_state
= nv50_head_atomic_duplicate_state
,
2387 .atomic_destroy_state
= nv50_head_atomic_destroy_state
,
2391 nv50_head_create(struct drm_device
*dev
, int index
)
2393 struct nouveau_drm
*drm
= nouveau_drm(dev
);
2394 struct nvif_device
*device
= &drm
->client
.device
;
2395 struct nv50_disp
*disp
= nv50_disp(dev
);
2396 struct nv50_head
*head
;
2397 struct nv50_base
*base
;
2398 struct nv50_curs
*curs
;
2399 struct drm_crtc
*crtc
;
2402 head
= kzalloc(sizeof(*head
), GFP_KERNEL
);
2406 head
->base
.index
= index
;
2407 ret
= nv50_base_new(drm
, head
, &base
);
2409 ret
= nv50_curs_new(drm
, head
, &curs
);
2415 crtc
= &head
->base
.base
;
2416 drm_crtc_init_with_planes(dev
, crtc
, &base
->wndw
.plane
,
2417 &curs
->wndw
.plane
, &nv50_head_func
,
2418 "head-%d", head
->base
.index
);
2419 drm_crtc_helper_add(crtc
, &nv50_head_help
);
2420 drm_mode_crtc_set_gamma_size(crtc
, 256);
2422 for (i
= 0; i
< ARRAY_SIZE(head
->lut
.nvbo
); i
++) {
2423 ret
= nouveau_bo_new_pin_map(&drm
->client
, 1025 * 8, 0x100,
2425 &head
->lut
.nvbo
[i
]);
2430 /* allocate overlay resources */
2431 ret
= nv50_oimm_create(device
, disp
->disp
, index
, &head
->oimm
);
2435 ret
= nv50_ovly_create(device
, disp
->disp
, index
, disp
->sync
->bo
.offset
,
2442 nv50_head_destroy(crtc
);
2446 /******************************************************************************
2447 * Output path helpers
2448 *****************************************************************************/
2450 nv50_outp_release(struct nouveau_encoder
*nv_encoder
)
2452 struct nv50_disp
*disp
= nv50_disp(nv_encoder
->base
.base
.dev
);
2454 struct nv50_disp_mthd_v1 base
;
2457 .base
.method
= NV50_DISP_MTHD_V1_RELEASE
,
2458 .base
.hasht
= nv_encoder
->dcb
->hasht
,
2459 .base
.hashm
= nv_encoder
->dcb
->hashm
,
2462 nvif_mthd(disp
->disp
, 0, &args
, sizeof(args
));
2463 nv_encoder
->or = -1;
2464 nv_encoder
->link
= 0;
2468 nv50_outp_acquire(struct nouveau_encoder
*nv_encoder
)
2470 struct nouveau_drm
*drm
= nouveau_drm(nv_encoder
->base
.base
.dev
);
2471 struct nv50_disp
*disp
= nv50_disp(drm
->dev
);
2473 struct nv50_disp_mthd_v1 base
;
2474 struct nv50_disp_acquire_v0 info
;
2477 .base
.method
= NV50_DISP_MTHD_V1_ACQUIRE
,
2478 .base
.hasht
= nv_encoder
->dcb
->hasht
,
2479 .base
.hashm
= nv_encoder
->dcb
->hashm
,
2483 ret
= nvif_mthd(disp
->disp
, 0, &args
, sizeof(args
));
2485 NV_ERROR(drm
, "error acquiring output path: %d\n", ret
);
2489 nv_encoder
->or = args
.info
.or;
2490 nv_encoder
->link
= args
.info
.link
;
2495 nv50_outp_atomic_check_view(struct drm_encoder
*encoder
,
2496 struct drm_crtc_state
*crtc_state
,
2497 struct drm_connector_state
*conn_state
,
2498 struct drm_display_mode
*native_mode
)
2500 struct drm_display_mode
*adjusted_mode
= &crtc_state
->adjusted_mode
;
2501 struct drm_display_mode
*mode
= &crtc_state
->mode
;
2502 struct drm_connector
*connector
= conn_state
->connector
;
2503 struct nouveau_conn_atom
*asyc
= nouveau_conn_atom(conn_state
);
2504 struct nouveau_drm
*drm
= nouveau_drm(encoder
->dev
);
2506 NV_ATOMIC(drm
, "%s atomic_check\n", encoder
->name
);
2507 asyc
->scaler
.full
= false;
2511 if (asyc
->scaler
.mode
== DRM_MODE_SCALE_NONE
) {
2512 switch (connector
->connector_type
) {
2513 case DRM_MODE_CONNECTOR_LVDS
:
2514 case DRM_MODE_CONNECTOR_eDP
:
2515 /* Force use of scaler for non-EDID modes. */
2516 if (adjusted_mode
->type
& DRM_MODE_TYPE_DRIVER
)
2519 asyc
->scaler
.full
= true;
2528 if (!drm_mode_equal(adjusted_mode
, mode
)) {
2529 drm_mode_copy(adjusted_mode
, mode
);
2530 crtc_state
->mode_changed
= true;
2537 nv50_outp_atomic_check(struct drm_encoder
*encoder
,
2538 struct drm_crtc_state
*crtc_state
,
2539 struct drm_connector_state
*conn_state
)
2541 struct nouveau_connector
*nv_connector
=
2542 nouveau_connector(conn_state
->connector
);
2543 return nv50_outp_atomic_check_view(encoder
, crtc_state
, conn_state
,
2544 nv_connector
->native_mode
);
2547 /******************************************************************************
2549 *****************************************************************************/
2551 nv50_dac_disable(struct drm_encoder
*encoder
)
2553 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2554 struct nv50_mast
*mast
= nv50_mast(encoder
->dev
);
2555 const int or = nv_encoder
->or;
2558 if (nv_encoder
->crtc
) {
2559 push
= evo_wait(mast
, 4);
2561 if (nv50_vers(mast
) < GF110_DISP_CORE_CHANNEL_DMA
) {
2562 evo_mthd(push
, 0x0400 + (or * 0x080), 1);
2563 evo_data(push
, 0x00000000);
2565 evo_mthd(push
, 0x0180 + (or * 0x020), 1);
2566 evo_data(push
, 0x00000000);
2568 evo_kick(push
, mast
);
2572 nv_encoder
->crtc
= NULL
;
2573 nv50_outp_release(nv_encoder
);
2577 nv50_dac_enable(struct drm_encoder
*encoder
)
2579 struct nv50_mast
*mast
= nv50_mast(encoder
->dev
);
2580 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2581 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
2582 struct drm_display_mode
*mode
= &nv_crtc
->base
.state
->adjusted_mode
;
2585 nv50_outp_acquire(nv_encoder
);
2587 push
= evo_wait(mast
, 8);
2589 if (nv50_vers(mast
) < GF110_DISP_CORE_CHANNEL_DMA
) {
2590 u32 syncs
= 0x00000000;
2592 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
2593 syncs
|= 0x00000001;
2594 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
2595 syncs
|= 0x00000002;
2597 evo_mthd(push
, 0x0400 + (nv_encoder
->or * 0x080), 2);
2598 evo_data(push
, 1 << nv_crtc
->index
);
2599 evo_data(push
, syncs
);
2601 u32 magic
= 0x31ec6000 | (nv_crtc
->index
<< 25);
2602 u32 syncs
= 0x00000001;
2604 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
2605 syncs
|= 0x00000008;
2606 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
2607 syncs
|= 0x00000010;
2609 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
2610 magic
|= 0x00000001;
2612 evo_mthd(push
, 0x0404 + (nv_crtc
->index
* 0x300), 2);
2613 evo_data(push
, syncs
);
2614 evo_data(push
, magic
);
2615 evo_mthd(push
, 0x0180 + (nv_encoder
->or * 0x020), 1);
2616 evo_data(push
, 1 << nv_crtc
->index
);
2619 evo_kick(push
, mast
);
2622 nv_encoder
->crtc
= encoder
->crtc
;
2625 static enum drm_connector_status
2626 nv50_dac_detect(struct drm_encoder
*encoder
, struct drm_connector
*connector
)
2628 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2629 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
2631 struct nv50_disp_mthd_v1 base
;
2632 struct nv50_disp_dac_load_v0 load
;
2635 .base
.method
= NV50_DISP_MTHD_V1_DAC_LOAD
,
2636 .base
.hasht
= nv_encoder
->dcb
->hasht
,
2637 .base
.hashm
= nv_encoder
->dcb
->hashm
,
2641 args
.load
.data
= nouveau_drm(encoder
->dev
)->vbios
.dactestval
;
2642 if (args
.load
.data
== 0)
2643 args
.load
.data
= 340;
2645 ret
= nvif_mthd(disp
->disp
, 0, &args
, sizeof(args
));
2646 if (ret
|| !args
.load
.load
)
2647 return connector_status_disconnected
;
2649 return connector_status_connected
;
2652 static const struct drm_encoder_helper_funcs
2654 .atomic_check
= nv50_outp_atomic_check
,
2655 .enable
= nv50_dac_enable
,
2656 .disable
= nv50_dac_disable
,
2657 .detect
= nv50_dac_detect
2661 nv50_dac_destroy(struct drm_encoder
*encoder
)
2663 drm_encoder_cleanup(encoder
);
2667 static const struct drm_encoder_funcs
2669 .destroy
= nv50_dac_destroy
,
2673 nv50_dac_create(struct drm_connector
*connector
, struct dcb_output
*dcbe
)
2675 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
2676 struct nvkm_i2c
*i2c
= nvxx_i2c(&drm
->client
.device
);
2677 struct nvkm_i2c_bus
*bus
;
2678 struct nouveau_encoder
*nv_encoder
;
2679 struct drm_encoder
*encoder
;
2680 int type
= DRM_MODE_ENCODER_DAC
;
2682 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
2685 nv_encoder
->dcb
= dcbe
;
2687 bus
= nvkm_i2c_bus_find(i2c
, dcbe
->i2c_index
);
2689 nv_encoder
->i2c
= &bus
->i2c
;
2691 encoder
= to_drm_encoder(nv_encoder
);
2692 encoder
->possible_crtcs
= dcbe
->heads
;
2693 encoder
->possible_clones
= 0;
2694 drm_encoder_init(connector
->dev
, encoder
, &nv50_dac_func
, type
,
2695 "dac-%04x-%04x", dcbe
->hasht
, dcbe
->hashm
);
2696 drm_encoder_helper_add(encoder
, &nv50_dac_help
);
2698 drm_mode_connector_attach_encoder(connector
, encoder
);
2702 /******************************************************************************
2704 *****************************************************************************/
2706 nv50_audio_disable(struct drm_encoder
*encoder
, struct nouveau_crtc
*nv_crtc
)
2708 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2709 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
2711 struct nv50_disp_mthd_v1 base
;
2712 struct nv50_disp_sor_hda_eld_v0 eld
;
2715 .base
.method
= NV50_DISP_MTHD_V1_SOR_HDA_ELD
,
2716 .base
.hasht
= nv_encoder
->dcb
->hasht
,
2717 .base
.hashm
= (0xf0ff & nv_encoder
->dcb
->hashm
) |
2718 (0x0100 << nv_crtc
->index
),
2721 nvif_mthd(disp
->disp
, 0, &args
, sizeof(args
));
2725 nv50_audio_enable(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
)
2727 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2728 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
2729 struct nouveau_connector
*nv_connector
;
2730 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
2733 struct nv50_disp_mthd_v1 mthd
;
2734 struct nv50_disp_sor_hda_eld_v0 eld
;
2736 u8 data
[sizeof(nv_connector
->base
.eld
)];
2738 .base
.mthd
.version
= 1,
2739 .base
.mthd
.method
= NV50_DISP_MTHD_V1_SOR_HDA_ELD
,
2740 .base
.mthd
.hasht
= nv_encoder
->dcb
->hasht
,
2741 .base
.mthd
.hashm
= (0xf0ff & nv_encoder
->dcb
->hashm
) |
2742 (0x0100 << nv_crtc
->index
),
2745 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
2746 if (!drm_detect_monitor_audio(nv_connector
->edid
))
2749 memcpy(args
.data
, nv_connector
->base
.eld
, sizeof(args
.data
));
2751 nvif_mthd(disp
->disp
, 0, &args
,
2752 sizeof(args
.base
) + drm_eld_size(args
.data
));
2755 /******************************************************************************
2757 *****************************************************************************/
2759 nv50_hdmi_disable(struct drm_encoder
*encoder
, struct nouveau_crtc
*nv_crtc
)
2761 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2762 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
2764 struct nv50_disp_mthd_v1 base
;
2765 struct nv50_disp_sor_hdmi_pwr_v0 pwr
;
2768 .base
.method
= NV50_DISP_MTHD_V1_SOR_HDMI_PWR
,
2769 .base
.hasht
= nv_encoder
->dcb
->hasht
,
2770 .base
.hashm
= (0xf0ff & nv_encoder
->dcb
->hashm
) |
2771 (0x0100 << nv_crtc
->index
),
2774 nvif_mthd(disp
->disp
, 0, &args
, sizeof(args
));
2778 nv50_hdmi_enable(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
)
2780 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
2781 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
2782 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
2784 struct nv50_disp_mthd_v1 base
;
2785 struct nv50_disp_sor_hdmi_pwr_v0 pwr
;
2786 u8 infoframes
[2 * 17]; /* two frames, up to 17 bytes each */
2789 .base
.method
= NV50_DISP_MTHD_V1_SOR_HDMI_PWR
,
2790 .base
.hasht
= nv_encoder
->dcb
->hasht
,
2791 .base
.hashm
= (0xf0ff & nv_encoder
->dcb
->hashm
) |
2792 (0x0100 << nv_crtc
->index
),
2794 .pwr
.rekey
= 56, /* binary driver, and tegra, constant */
2796 struct nouveau_connector
*nv_connector
;
2798 union hdmi_infoframe avi_frame
;
2799 union hdmi_infoframe vendor_frame
;
2803 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
2804 if (!drm_detect_hdmi_monitor(nv_connector
->edid
))
2807 ret
= drm_hdmi_avi_infoframe_from_display_mode(&avi_frame
.avi
, mode
,
2810 /* We have an AVI InfoFrame, populate it to the display */
2811 args
.pwr
.avi_infoframe_length
2812 = hdmi_infoframe_pack(&avi_frame
, args
.infoframes
, 17);
2815 ret
= drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame
.vendor
.hdmi
,
2816 &nv_connector
->base
, mode
);
2818 /* We have a Vendor InfoFrame, populate it to the display */
2819 args
.pwr
.vendor_infoframe_length
2820 = hdmi_infoframe_pack(&vendor_frame
,
2822 + args
.pwr
.avi_infoframe_length
,
2826 max_ac_packet
= mode
->htotal
- mode
->hdisplay
;
2827 max_ac_packet
-= args
.pwr
.rekey
;
2828 max_ac_packet
-= 18; /* constant from tegra */
2829 args
.pwr
.max_ac_packet
= max_ac_packet
/ 32;
2831 size
= sizeof(args
.base
)
2833 + args
.pwr
.avi_infoframe_length
2834 + args
.pwr
.vendor_infoframe_length
;
2835 nvif_mthd(disp
->disp
, 0, &args
, size
);
2836 nv50_audio_enable(encoder
, mode
);
2839 /******************************************************************************
2841 *****************************************************************************/
2842 #define nv50_mstm(p) container_of((p), struct nv50_mstm, mgr)
2843 #define nv50_mstc(p) container_of((p), struct nv50_mstc, connector)
2844 #define nv50_msto(p) container_of((p), struct nv50_msto, encoder)
2847 struct nouveau_encoder
*outp
;
2849 struct drm_dp_mst_topology_mgr mgr
;
2850 struct nv50_msto
*msto
[4];
2858 struct nv50_mstm
*mstm
;
2859 struct drm_dp_mst_port
*port
;
2860 struct drm_connector connector
;
2862 struct drm_display_mode
*native
;
2869 struct drm_encoder encoder
;
2871 struct nv50_head
*head
;
2872 struct nv50_mstc
*mstc
;
2876 static struct drm_dp_payload
*
2877 nv50_msto_payload(struct nv50_msto
*msto
)
2879 struct nouveau_drm
*drm
= nouveau_drm(msto
->encoder
.dev
);
2880 struct nv50_mstc
*mstc
= msto
->mstc
;
2881 struct nv50_mstm
*mstm
= mstc
->mstm
;
2882 int vcpi
= mstc
->port
->vcpi
.vcpi
, i
;
2884 NV_ATOMIC(drm
, "%s: vcpi %d\n", msto
->encoder
.name
, vcpi
);
2885 for (i
= 0; i
< mstm
->mgr
.max_payloads
; i
++) {
2886 struct drm_dp_payload
*payload
= &mstm
->mgr
.payloads
[i
];
2887 NV_ATOMIC(drm
, "%s: %d: vcpi %d start 0x%02x slots 0x%02x\n",
2888 mstm
->outp
->base
.base
.name
, i
, payload
->vcpi
,
2889 payload
->start_slot
, payload
->num_slots
);
2892 for (i
= 0; i
< mstm
->mgr
.max_payloads
; i
++) {
2893 struct drm_dp_payload
*payload
= &mstm
->mgr
.payloads
[i
];
2894 if (payload
->vcpi
== vcpi
)
2902 nv50_msto_cleanup(struct nv50_msto
*msto
)
2904 struct nouveau_drm
*drm
= nouveau_drm(msto
->encoder
.dev
);
2905 struct nv50_mstc
*mstc
= msto
->mstc
;
2906 struct nv50_mstm
*mstm
= mstc
->mstm
;
2908 NV_ATOMIC(drm
, "%s: msto cleanup\n", msto
->encoder
.name
);
2909 if (mstc
->port
&& mstc
->port
->vcpi
.vcpi
> 0 && !nv50_msto_payload(msto
))
2910 drm_dp_mst_deallocate_vcpi(&mstm
->mgr
, mstc
->port
);
2911 if (msto
->disabled
) {
2914 msto
->disabled
= false;
2919 nv50_msto_prepare(struct nv50_msto
*msto
)
2921 struct nouveau_drm
*drm
= nouveau_drm(msto
->encoder
.dev
);
2922 struct nv50_mstc
*mstc
= msto
->mstc
;
2923 struct nv50_mstm
*mstm
= mstc
->mstm
;
2925 struct nv50_disp_mthd_v1 base
;
2926 struct nv50_disp_sor_dp_mst_vcpi_v0 vcpi
;
2929 .base
.method
= NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI
,
2930 .base
.hasht
= mstm
->outp
->dcb
->hasht
,
2931 .base
.hashm
= (0xf0ff & mstm
->outp
->dcb
->hashm
) |
2932 (0x0100 << msto
->head
->base
.index
),
2935 NV_ATOMIC(drm
, "%s: msto prepare\n", msto
->encoder
.name
);
2936 if (mstc
->port
&& mstc
->port
->vcpi
.vcpi
> 0) {
2937 struct drm_dp_payload
*payload
= nv50_msto_payload(msto
);
2939 args
.vcpi
.start_slot
= payload
->start_slot
;
2940 args
.vcpi
.num_slots
= payload
->num_slots
;
2941 args
.vcpi
.pbn
= mstc
->port
->vcpi
.pbn
;
2942 args
.vcpi
.aligned_pbn
= mstc
->port
->vcpi
.aligned_pbn
;
2946 NV_ATOMIC(drm
, "%s: %s: %02x %02x %04x %04x\n",
2947 msto
->encoder
.name
, msto
->head
->base
.base
.name
,
2948 args
.vcpi
.start_slot
, args
.vcpi
.num_slots
,
2949 args
.vcpi
.pbn
, args
.vcpi
.aligned_pbn
);
2950 nvif_mthd(&drm
->display
->disp
, 0, &args
, sizeof(args
));
2954 nv50_msto_atomic_check(struct drm_encoder
*encoder
,
2955 struct drm_crtc_state
*crtc_state
,
2956 struct drm_connector_state
*conn_state
)
2958 struct nv50_mstc
*mstc
= nv50_mstc(conn_state
->connector
);
2959 struct nv50_mstm
*mstm
= mstc
->mstm
;
2960 int bpp
= conn_state
->connector
->display_info
.bpc
* 3;
2963 mstc
->pbn
= drm_dp_calc_pbn_mode(crtc_state
->adjusted_mode
.clock
, bpp
);
2965 slots
= drm_dp_find_vcpi_slots(&mstm
->mgr
, mstc
->pbn
);
2969 return nv50_outp_atomic_check_view(encoder
, crtc_state
, conn_state
,
2974 nv50_msto_enable(struct drm_encoder
*encoder
)
2976 struct nv50_head
*head
= nv50_head(encoder
->crtc
);
2977 struct nv50_msto
*msto
= nv50_msto(encoder
);
2978 struct nv50_mstc
*mstc
= NULL
;
2979 struct nv50_mstm
*mstm
= NULL
;
2980 struct drm_connector
*connector
;
2981 struct drm_connector_list_iter conn_iter
;
2986 drm_connector_list_iter_begin(encoder
->dev
, &conn_iter
);
2987 drm_for_each_connector_iter(connector
, &conn_iter
) {
2988 if (connector
->state
->best_encoder
== &msto
->encoder
) {
2989 mstc
= nv50_mstc(connector
);
2994 drm_connector_list_iter_end(&conn_iter
);
2999 slots
= drm_dp_find_vcpi_slots(&mstm
->mgr
, mstc
->pbn
);
3000 r
= drm_dp_mst_allocate_vcpi(&mstm
->mgr
, mstc
->port
, mstc
->pbn
, slots
);
3004 nv50_outp_acquire(mstm
->outp
);
3006 if (mstm
->outp
->link
& 1)
3011 switch (mstc
->connector
.display_info
.bpc
) {
3012 case 6: depth
= 0x2; break;
3013 case 8: depth
= 0x5; break;
3015 default: depth
= 0x6; break;
3018 mstm
->outp
->update(mstm
->outp
, head
->base
.index
,
3019 &head
->base
.base
.state
->adjusted_mode
, proto
, depth
);
3023 mstm
->modified
= true;
3027 nv50_msto_disable(struct drm_encoder
*encoder
)
3029 struct nv50_msto
*msto
= nv50_msto(encoder
);
3030 struct nv50_mstc
*mstc
= msto
->mstc
;
3031 struct nv50_mstm
*mstm
= mstc
->mstm
;
3034 drm_dp_mst_reset_vcpi_slots(&mstm
->mgr
, mstc
->port
);
3036 mstm
->outp
->update(mstm
->outp
, msto
->head
->base
.index
, NULL
, 0, 0);
3037 mstm
->modified
= true;
3039 mstm
->disabled
= true;
3040 msto
->disabled
= true;
3043 static const struct drm_encoder_helper_funcs
3045 .disable
= nv50_msto_disable
,
3046 .enable
= nv50_msto_enable
,
3047 .atomic_check
= nv50_msto_atomic_check
,
3051 nv50_msto_destroy(struct drm_encoder
*encoder
)
3053 struct nv50_msto
*msto
= nv50_msto(encoder
);
3054 drm_encoder_cleanup(&msto
->encoder
);
3058 static const struct drm_encoder_funcs
3060 .destroy
= nv50_msto_destroy
,
3064 nv50_msto_new(struct drm_device
*dev
, u32 heads
, const char *name
, int id
,
3065 struct nv50_msto
**pmsto
)
3067 struct nv50_msto
*msto
;
3070 if (!(msto
= *pmsto
= kzalloc(sizeof(*msto
), GFP_KERNEL
)))
3073 ret
= drm_encoder_init(dev
, &msto
->encoder
, &nv50_msto
,
3074 DRM_MODE_ENCODER_DPMST
, "%s-mst-%d", name
, id
);
3081 drm_encoder_helper_add(&msto
->encoder
, &nv50_msto_help
);
3082 msto
->encoder
.possible_crtcs
= heads
;
3086 static struct drm_encoder
*
3087 nv50_mstc_atomic_best_encoder(struct drm_connector
*connector
,
3088 struct drm_connector_state
*connector_state
)
3090 struct nv50_head
*head
= nv50_head(connector_state
->crtc
);
3091 struct nv50_mstc
*mstc
= nv50_mstc(connector
);
3093 struct nv50_mstm
*mstm
= mstc
->mstm
;
3094 return &mstm
->msto
[head
->base
.index
]->encoder
;
3099 static struct drm_encoder
*
3100 nv50_mstc_best_encoder(struct drm_connector
*connector
)
3102 struct nv50_mstc
*mstc
= nv50_mstc(connector
);
3104 struct nv50_mstm
*mstm
= mstc
->mstm
;
3105 return &mstm
->msto
[0]->encoder
;
3110 static enum drm_mode_status
3111 nv50_mstc_mode_valid(struct drm_connector
*connector
,
3112 struct drm_display_mode
*mode
)
3118 nv50_mstc_get_modes(struct drm_connector
*connector
)
3120 struct nv50_mstc
*mstc
= nv50_mstc(connector
);
3123 mstc
->edid
= drm_dp_mst_get_edid(&mstc
->connector
, mstc
->port
->mgr
, mstc
->port
);
3124 drm_mode_connector_update_edid_property(&mstc
->connector
, mstc
->edid
);
3126 ret
= drm_add_edid_modes(&mstc
->connector
, mstc
->edid
);
3128 if (!mstc
->connector
.display_info
.bpc
)
3129 mstc
->connector
.display_info
.bpc
= 8;
3132 drm_mode_destroy(mstc
->connector
.dev
, mstc
->native
);
3133 mstc
->native
= nouveau_conn_native_mode(&mstc
->connector
);
3137 static const struct drm_connector_helper_funcs
3139 .get_modes
= nv50_mstc_get_modes
,
3140 .mode_valid
= nv50_mstc_mode_valid
,
3141 .best_encoder
= nv50_mstc_best_encoder
,
3142 .atomic_best_encoder
= nv50_mstc_atomic_best_encoder
,
3145 static enum drm_connector_status
3146 nv50_mstc_detect(struct drm_connector
*connector
, bool force
)
3148 struct nv50_mstc
*mstc
= nv50_mstc(connector
);
3150 return connector_status_disconnected
;
3151 return drm_dp_mst_detect_port(connector
, mstc
->port
->mgr
, mstc
->port
);
3155 nv50_mstc_destroy(struct drm_connector
*connector
)
3157 struct nv50_mstc
*mstc
= nv50_mstc(connector
);
3158 drm_connector_cleanup(&mstc
->connector
);
3162 static const struct drm_connector_funcs
3164 .reset
= nouveau_conn_reset
,
3165 .detect
= nv50_mstc_detect
,
3166 .fill_modes
= drm_helper_probe_single_connector_modes
,
3167 .destroy
= nv50_mstc_destroy
,
3168 .atomic_duplicate_state
= nouveau_conn_atomic_duplicate_state
,
3169 .atomic_destroy_state
= nouveau_conn_atomic_destroy_state
,
3170 .atomic_set_property
= nouveau_conn_atomic_set_property
,
3171 .atomic_get_property
= nouveau_conn_atomic_get_property
,
3175 nv50_mstc_new(struct nv50_mstm
*mstm
, struct drm_dp_mst_port
*port
,
3176 const char *path
, struct nv50_mstc
**pmstc
)
3178 struct drm_device
*dev
= mstm
->outp
->base
.base
.dev
;
3179 struct nv50_mstc
*mstc
;
3182 if (!(mstc
= *pmstc
= kzalloc(sizeof(*mstc
), GFP_KERNEL
)))
3187 ret
= drm_connector_init(dev
, &mstc
->connector
, &nv50_mstc
,
3188 DRM_MODE_CONNECTOR_DisplayPort
);
3195 drm_connector_helper_add(&mstc
->connector
, &nv50_mstc_help
);
3197 mstc
->connector
.funcs
->reset(&mstc
->connector
);
3198 nouveau_conn_attach_properties(&mstc
->connector
);
3200 for (i
= 0; i
< ARRAY_SIZE(mstm
->msto
) && mstm
->msto
[i
]; i
++)
3201 drm_mode_connector_attach_encoder(&mstc
->connector
, &mstm
->msto
[i
]->encoder
);
3203 drm_object_attach_property(&mstc
->connector
.base
, dev
->mode_config
.path_property
, 0);
3204 drm_object_attach_property(&mstc
->connector
.base
, dev
->mode_config
.tile_property
, 0);
3205 drm_mode_connector_set_path_property(&mstc
->connector
, path
);
3210 nv50_mstm_cleanup(struct nv50_mstm
*mstm
)
3212 struct nouveau_drm
*drm
= nouveau_drm(mstm
->outp
->base
.base
.dev
);
3213 struct drm_encoder
*encoder
;
3216 NV_ATOMIC(drm
, "%s: mstm cleanup\n", mstm
->outp
->base
.base
.name
);
3217 ret
= drm_dp_check_act_status(&mstm
->mgr
);
3219 ret
= drm_dp_update_payload_part2(&mstm
->mgr
);
3221 drm_for_each_encoder(encoder
, mstm
->outp
->base
.base
.dev
) {
3222 if (encoder
->encoder_type
== DRM_MODE_ENCODER_DPMST
) {
3223 struct nv50_msto
*msto
= nv50_msto(encoder
);
3224 struct nv50_mstc
*mstc
= msto
->mstc
;
3225 if (mstc
&& mstc
->mstm
== mstm
)
3226 nv50_msto_cleanup(msto
);
3230 mstm
->modified
= false;
3234 nv50_mstm_prepare(struct nv50_mstm
*mstm
)
3236 struct nouveau_drm
*drm
= nouveau_drm(mstm
->outp
->base
.base
.dev
);
3237 struct drm_encoder
*encoder
;
3240 NV_ATOMIC(drm
, "%s: mstm prepare\n", mstm
->outp
->base
.base
.name
);
3241 ret
= drm_dp_update_payload_part1(&mstm
->mgr
);
3243 drm_for_each_encoder(encoder
, mstm
->outp
->base
.base
.dev
) {
3244 if (encoder
->encoder_type
== DRM_MODE_ENCODER_DPMST
) {
3245 struct nv50_msto
*msto
= nv50_msto(encoder
);
3246 struct nv50_mstc
*mstc
= msto
->mstc
;
3247 if (mstc
&& mstc
->mstm
== mstm
)
3248 nv50_msto_prepare(msto
);
3252 if (mstm
->disabled
) {
3254 nv50_outp_release(mstm
->outp
);
3255 mstm
->disabled
= false;
3260 nv50_mstm_hotplug(struct drm_dp_mst_topology_mgr
*mgr
)
3262 struct nv50_mstm
*mstm
= nv50_mstm(mgr
);
3263 drm_kms_helper_hotplug_event(mstm
->outp
->base
.base
.dev
);
3267 nv50_mstm_destroy_connector(struct drm_dp_mst_topology_mgr
*mgr
,
3268 struct drm_connector
*connector
)
3270 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
3271 struct nv50_mstc
*mstc
= nv50_mstc(connector
);
3273 drm_connector_unregister(&mstc
->connector
);
3275 drm_modeset_lock_all(drm
->dev
);
3276 drm_fb_helper_remove_one_connector(&drm
->fbcon
->helper
, &mstc
->connector
);
3278 drm_modeset_unlock_all(drm
->dev
);
3280 drm_connector_unreference(&mstc
->connector
);
3284 nv50_mstm_register_connector(struct drm_connector
*connector
)
3286 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
3288 drm_modeset_lock_all(drm
->dev
);
3289 drm_fb_helper_add_one_connector(&drm
->fbcon
->helper
, connector
);
3290 drm_modeset_unlock_all(drm
->dev
);
3292 drm_connector_register(connector
);
3295 static struct drm_connector
*
3296 nv50_mstm_add_connector(struct drm_dp_mst_topology_mgr
*mgr
,
3297 struct drm_dp_mst_port
*port
, const char *path
)
3299 struct nv50_mstm
*mstm
= nv50_mstm(mgr
);
3300 struct nv50_mstc
*mstc
;
3303 ret
= nv50_mstc_new(mstm
, port
, path
, &mstc
);
3306 mstc
->connector
.funcs
->destroy(&mstc
->connector
);
3310 return &mstc
->connector
;
3313 static const struct drm_dp_mst_topology_cbs
3315 .add_connector
= nv50_mstm_add_connector
,
3316 .register_connector
= nv50_mstm_register_connector
,
3317 .destroy_connector
= nv50_mstm_destroy_connector
,
3318 .hotplug
= nv50_mstm_hotplug
,
3322 nv50_mstm_service(struct nv50_mstm
*mstm
)
3324 struct drm_dp_aux
*aux
= mstm
? mstm
->mgr
.aux
: NULL
;
3325 bool handled
= true;
3333 ret
= drm_dp_dpcd_read(aux
, DP_SINK_COUNT_ESI
, esi
, 8);
3335 drm_dp_mst_topology_mgr_set_mst(&mstm
->mgr
, false);
3339 drm_dp_mst_hpd_irq(&mstm
->mgr
, esi
, &handled
);
3343 drm_dp_dpcd_write(aux
, DP_SINK_COUNT_ESI
+ 1, &esi
[1], 3);
3348 nv50_mstm_remove(struct nv50_mstm
*mstm
)
3351 drm_dp_mst_topology_mgr_set_mst(&mstm
->mgr
, false);
3355 nv50_mstm_enable(struct nv50_mstm
*mstm
, u8 dpcd
, int state
)
3357 struct nouveau_encoder
*outp
= mstm
->outp
;
3359 struct nv50_disp_mthd_v1 base
;
3360 struct nv50_disp_sor_dp_mst_link_v0 mst
;
3363 .base
.method
= NV50_DISP_MTHD_V1_SOR_DP_MST_LINK
,
3364 .base
.hasht
= outp
->dcb
->hasht
,
3365 .base
.hashm
= outp
->dcb
->hashm
,
3368 struct nouveau_drm
*drm
= nouveau_drm(outp
->base
.base
.dev
);
3369 struct nvif_object
*disp
= &drm
->display
->disp
;
3373 ret
= drm_dp_dpcd_readb(mstm
->mgr
.aux
, DP_MSTM_CTRL
, &dpcd
);
3381 ret
= drm_dp_dpcd_writeb(mstm
->mgr
.aux
, DP_MSTM_CTRL
, dpcd
);
3386 return nvif_mthd(disp
, 0, &args
, sizeof(args
));
3390 nv50_mstm_detect(struct nv50_mstm
*mstm
, u8 dpcd
[8], int allow
)
3397 if (dpcd
[0] >= 0x12) {
3398 ret
= drm_dp_dpcd_readb(mstm
->mgr
.aux
, DP_MSTM_CAP
, &dpcd
[1]);
3402 if (!(dpcd
[1] & DP_MST_CAP
))
3408 ret
= nv50_mstm_enable(mstm
, dpcd
[0], state
);
3412 ret
= drm_dp_mst_topology_mgr_set_mst(&mstm
->mgr
, state
);
3414 return nv50_mstm_enable(mstm
, dpcd
[0], 0);
3416 return mstm
->mgr
.mst_state
;
3420 nv50_mstm_fini(struct nv50_mstm
*mstm
)
3422 if (mstm
&& mstm
->mgr
.mst_state
)
3423 drm_dp_mst_topology_mgr_suspend(&mstm
->mgr
);
3427 nv50_mstm_init(struct nv50_mstm
*mstm
)
3429 if (mstm
&& mstm
->mgr
.mst_state
)
3430 drm_dp_mst_topology_mgr_resume(&mstm
->mgr
);
3434 nv50_mstm_del(struct nv50_mstm
**pmstm
)
3436 struct nv50_mstm
*mstm
= *pmstm
;
3444 nv50_mstm_new(struct nouveau_encoder
*outp
, struct drm_dp_aux
*aux
, int aux_max
,
3445 int conn_base_id
, struct nv50_mstm
**pmstm
)
3447 const int max_payloads
= hweight8(outp
->dcb
->heads
);
3448 struct drm_device
*dev
= outp
->base
.base
.dev
;
3449 struct nv50_mstm
*mstm
;
3453 /* This is a workaround for some monitors not functioning
3454 * correctly in MST mode on initial module load. I think
3455 * some bad interaction with the VBIOS may be responsible.
3457 * A good ol' off and on again seems to work here ;)
3459 ret
= drm_dp_dpcd_readb(aux
, DP_DPCD_REV
, &dpcd
);
3460 if (ret
>= 0 && dpcd
>= 0x12)
3461 drm_dp_dpcd_writeb(aux
, DP_MSTM_CTRL
, 0);
3463 if (!(mstm
= *pmstm
= kzalloc(sizeof(*mstm
), GFP_KERNEL
)))
3466 mstm
->mgr
.cbs
= &nv50_mstm
;
3468 ret
= drm_dp_mst_topology_mgr_init(&mstm
->mgr
, dev
, aux
, aux_max
,
3469 max_payloads
, conn_base_id
);
3473 for (i
= 0; i
< max_payloads
; i
++) {
3474 ret
= nv50_msto_new(dev
, outp
->dcb
->heads
, outp
->base
.base
.name
,
3483 /******************************************************************************
3485 *****************************************************************************/
3487 nv50_sor_update(struct nouveau_encoder
*nv_encoder
, u8 head
,
3488 struct drm_display_mode
*mode
, u8 proto
, u8 depth
)
3490 struct nv50_dmac
*core
= &nv50_mast(nv_encoder
->base
.base
.dev
)->base
;
3494 nv_encoder
->ctrl
&= ~BIT(head
);
3495 if (!(nv_encoder
->ctrl
& 0x0000000f))
3496 nv_encoder
->ctrl
= 0;
3498 nv_encoder
->ctrl
|= proto
<< 8;
3499 nv_encoder
->ctrl
|= BIT(head
);
3502 if ((push
= evo_wait(core
, 6))) {
3503 if (core
->base
.user
.oclass
< GF110_DISP_CORE_CHANNEL_DMA
) {
3505 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
3506 nv_encoder
->ctrl
|= 0x00001000;
3507 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
3508 nv_encoder
->ctrl
|= 0x00002000;
3509 nv_encoder
->ctrl
|= depth
<< 16;
3511 evo_mthd(push
, 0x0600 + (nv_encoder
->or * 0x40), 1);
3514 u32 magic
= 0x31ec6000 | (head
<< 25);
3515 u32 syncs
= 0x00000001;
3516 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
3517 syncs
|= 0x00000008;
3518 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
3519 syncs
|= 0x00000010;
3520 if (mode
->flags
& DRM_MODE_FLAG_INTERLACE
)
3521 magic
|= 0x00000001;
3523 evo_mthd(push
, 0x0404 + (head
* 0x300), 2);
3524 evo_data(push
, syncs
| (depth
<< 6));
3525 evo_data(push
, magic
);
3527 evo_mthd(push
, 0x0200 + (nv_encoder
->or * 0x20), 1);
3529 evo_data(push
, nv_encoder
->ctrl
);
3530 evo_kick(push
, core
);
3535 nv50_sor_disable(struct drm_encoder
*encoder
)
3537 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
3538 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(nv_encoder
->crtc
);
3540 nv_encoder
->crtc
= NULL
;
3543 struct nvkm_i2c_aux
*aux
= nv_encoder
->aux
;
3547 int ret
= nvkm_rdaux(aux
, DP_SET_POWER
, &pwr
, 1);
3549 pwr
&= ~DP_SET_POWER_MASK
;
3550 pwr
|= DP_SET_POWER_D3
;
3551 nvkm_wraux(aux
, DP_SET_POWER
, &pwr
, 1);
3555 nv_encoder
->update(nv_encoder
, nv_crtc
->index
, NULL
, 0, 0);
3556 nv50_audio_disable(encoder
, nv_crtc
);
3557 nv50_hdmi_disable(&nv_encoder
->base
.base
, nv_crtc
);
3558 nv50_outp_release(nv_encoder
);
3563 nv50_sor_enable(struct drm_encoder
*encoder
)
3565 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
3566 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
3567 struct drm_display_mode
*mode
= &nv_crtc
->base
.state
->adjusted_mode
;
3569 struct nv50_disp_mthd_v1 base
;
3570 struct nv50_disp_sor_lvds_script_v0 lvds
;
3573 .base
.method
= NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT
,
3574 .base
.hasht
= nv_encoder
->dcb
->hasht
,
3575 .base
.hashm
= nv_encoder
->dcb
->hashm
,
3577 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
3578 struct drm_device
*dev
= encoder
->dev
;
3579 struct nouveau_drm
*drm
= nouveau_drm(dev
);
3580 struct nouveau_connector
*nv_connector
;
3581 struct nvbios
*bios
= &drm
->vbios
;
3585 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
3586 nv_encoder
->crtc
= encoder
->crtc
;
3587 nv50_outp_acquire(nv_encoder
);
3589 switch (nv_encoder
->dcb
->type
) {
3590 case DCB_OUTPUT_TMDS
:
3591 if (nv_encoder
->link
& 1) {
3593 /* Only enable dual-link if:
3594 * - Need to (i.e. rate > 165MHz)
3596 * - Not an HDMI monitor, since there's no dual-link
3599 if (mode
->clock
>= 165000 &&
3600 nv_encoder
->dcb
->duallink_possible
&&
3601 !drm_detect_hdmi_monitor(nv_connector
->edid
))
3607 nv50_hdmi_enable(&nv_encoder
->base
.base
, mode
);
3609 case DCB_OUTPUT_LVDS
:
3612 if (bios
->fp_no_ddc
) {
3613 if (bios
->fp
.dual_link
)
3614 lvds
.lvds
.script
|= 0x0100;
3615 if (bios
->fp
.if_is_24bit
)
3616 lvds
.lvds
.script
|= 0x0200;
3618 if (nv_connector
->type
== DCB_CONNECTOR_LVDS_SPWG
) {
3619 if (((u8
*)nv_connector
->edid
)[121] == 2)
3620 lvds
.lvds
.script
|= 0x0100;
3622 if (mode
->clock
>= bios
->fp
.duallink_transition_clk
) {
3623 lvds
.lvds
.script
|= 0x0100;
3626 if (lvds
.lvds
.script
& 0x0100) {
3627 if (bios
->fp
.strapless_is_24bit
& 2)
3628 lvds
.lvds
.script
|= 0x0200;
3630 if (bios
->fp
.strapless_is_24bit
& 1)
3631 lvds
.lvds
.script
|= 0x0200;
3634 if (nv_connector
->base
.display_info
.bpc
== 8)
3635 lvds
.lvds
.script
|= 0x0200;
3638 nvif_mthd(disp
->disp
, 0, &lvds
, sizeof(lvds
));
3641 if (nv_connector
->base
.display_info
.bpc
== 6)
3644 if (nv_connector
->base
.display_info
.bpc
== 8)
3649 if (nv_encoder
->link
& 1)
3654 nv50_audio_enable(encoder
, mode
);
3661 nv_encoder
->update(nv_encoder
, nv_crtc
->index
, mode
, proto
, depth
);
3664 static const struct drm_encoder_helper_funcs
3666 .atomic_check
= nv50_outp_atomic_check
,
3667 .enable
= nv50_sor_enable
,
3668 .disable
= nv50_sor_disable
,
3672 nv50_sor_destroy(struct drm_encoder
*encoder
)
3674 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
3675 nv50_mstm_del(&nv_encoder
->dp
.mstm
);
3676 drm_encoder_cleanup(encoder
);
3680 static const struct drm_encoder_funcs
3682 .destroy
= nv50_sor_destroy
,
3686 nv50_sor_create(struct drm_connector
*connector
, struct dcb_output
*dcbe
)
3688 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
3689 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
3690 struct nvkm_i2c
*i2c
= nvxx_i2c(&drm
->client
.device
);
3691 struct nouveau_encoder
*nv_encoder
;
3692 struct drm_encoder
*encoder
;
3695 switch (dcbe
->type
) {
3696 case DCB_OUTPUT_LVDS
: type
= DRM_MODE_ENCODER_LVDS
; break;
3697 case DCB_OUTPUT_TMDS
:
3700 type
= DRM_MODE_ENCODER_TMDS
;
3704 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
3707 nv_encoder
->dcb
= dcbe
;
3708 nv_encoder
->update
= nv50_sor_update
;
3710 encoder
= to_drm_encoder(nv_encoder
);
3711 encoder
->possible_crtcs
= dcbe
->heads
;
3712 encoder
->possible_clones
= 0;
3713 drm_encoder_init(connector
->dev
, encoder
, &nv50_sor_func
, type
,
3714 "sor-%04x-%04x", dcbe
->hasht
, dcbe
->hashm
);
3715 drm_encoder_helper_add(encoder
, &nv50_sor_help
);
3717 drm_mode_connector_attach_encoder(connector
, encoder
);
3719 if (dcbe
->type
== DCB_OUTPUT_DP
) {
3720 struct nv50_disp
*disp
= nv50_disp(encoder
->dev
);
3721 struct nvkm_i2c_aux
*aux
=
3722 nvkm_i2c_aux_find(i2c
, dcbe
->i2c_index
);
3724 if (disp
->disp
->oclass
< GF110_DISP
) {
3725 /* HW has no support for address-only
3726 * transactions, so we're required to
3727 * use custom I2C-over-AUX code.
3729 nv_encoder
->i2c
= &aux
->i2c
;
3731 nv_encoder
->i2c
= &nv_connector
->aux
.ddc
;
3733 nv_encoder
->aux
= aux
;
3736 /*TODO: Use DP Info Table to check for support. */
3737 if (disp
->disp
->oclass
>= GF110_DISP
) {
3738 ret
= nv50_mstm_new(nv_encoder
, &nv_connector
->aux
, 16,
3739 nv_connector
->base
.base
.id
,
3740 &nv_encoder
->dp
.mstm
);
3745 struct nvkm_i2c_bus
*bus
=
3746 nvkm_i2c_bus_find(i2c
, dcbe
->i2c_index
);
3748 nv_encoder
->i2c
= &bus
->i2c
;
3754 /******************************************************************************
3756 *****************************************************************************/
3758 nv50_pior_atomic_check(struct drm_encoder
*encoder
,
3759 struct drm_crtc_state
*crtc_state
,
3760 struct drm_connector_state
*conn_state
)
3762 int ret
= nv50_outp_atomic_check(encoder
, crtc_state
, conn_state
);
3765 crtc_state
->adjusted_mode
.clock
*= 2;
3770 nv50_pior_disable(struct drm_encoder
*encoder
)
3772 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
3773 struct nv50_mast
*mast
= nv50_mast(encoder
->dev
);
3774 const int or = nv_encoder
->or;
3777 if (nv_encoder
->crtc
) {
3778 push
= evo_wait(mast
, 4);
3780 if (nv50_vers(mast
) < GF110_DISP_CORE_CHANNEL_DMA
) {
3781 evo_mthd(push
, 0x0700 + (or * 0x040), 1);
3782 evo_data(push
, 0x00000000);
3784 evo_kick(push
, mast
);
3788 nv_encoder
->crtc
= NULL
;
3789 nv50_outp_release(nv_encoder
);
3793 nv50_pior_enable(struct drm_encoder
*encoder
)
3795 struct nv50_mast
*mast
= nv50_mast(encoder
->dev
);
3796 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
3797 struct nouveau_crtc
*nv_crtc
= nouveau_crtc(encoder
->crtc
);
3798 struct nouveau_connector
*nv_connector
;
3799 struct drm_display_mode
*mode
= &nv_crtc
->base
.state
->adjusted_mode
;
3800 u8 owner
= 1 << nv_crtc
->index
;
3804 nv50_outp_acquire(nv_encoder
);
3806 nv_connector
= nouveau_encoder_connector_get(nv_encoder
);
3807 switch (nv_connector
->base
.display_info
.bpc
) {
3808 case 10: depth
= 0x6; break;
3809 case 8: depth
= 0x5; break;
3810 case 6: depth
= 0x2; break;
3811 default: depth
= 0x0; break;
3814 switch (nv_encoder
->dcb
->type
) {
3815 case DCB_OUTPUT_TMDS
:
3824 push
= evo_wait(mast
, 8);
3826 if (nv50_vers(mast
) < GF110_DISP_CORE_CHANNEL_DMA
) {
3827 u32 ctrl
= (depth
<< 16) | (proto
<< 8) | owner
;
3828 if (mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
3830 if (mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
3832 evo_mthd(push
, 0x0700 + (nv_encoder
->or * 0x040), 1);
3833 evo_data(push
, ctrl
);
3836 evo_kick(push
, mast
);
3839 nv_encoder
->crtc
= encoder
->crtc
;
3842 static const struct drm_encoder_helper_funcs
3844 .atomic_check
= nv50_pior_atomic_check
,
3845 .enable
= nv50_pior_enable
,
3846 .disable
= nv50_pior_disable
,
3850 nv50_pior_destroy(struct drm_encoder
*encoder
)
3852 drm_encoder_cleanup(encoder
);
3856 static const struct drm_encoder_funcs
3858 .destroy
= nv50_pior_destroy
,
3862 nv50_pior_create(struct drm_connector
*connector
, struct dcb_output
*dcbe
)
3864 struct nouveau_connector
*nv_connector
= nouveau_connector(connector
);
3865 struct nouveau_drm
*drm
= nouveau_drm(connector
->dev
);
3866 struct nvkm_i2c
*i2c
= nvxx_i2c(&drm
->client
.device
);
3867 struct nvkm_i2c_bus
*bus
= NULL
;
3868 struct nvkm_i2c_aux
*aux
= NULL
;
3869 struct i2c_adapter
*ddc
;
3870 struct nouveau_encoder
*nv_encoder
;
3871 struct drm_encoder
*encoder
;
3874 switch (dcbe
->type
) {
3875 case DCB_OUTPUT_TMDS
:
3876 bus
= nvkm_i2c_bus_find(i2c
, NVKM_I2C_BUS_EXT(dcbe
->extdev
));
3877 ddc
= bus
? &bus
->i2c
: NULL
;
3878 type
= DRM_MODE_ENCODER_TMDS
;
3881 aux
= nvkm_i2c_aux_find(i2c
, NVKM_I2C_AUX_EXT(dcbe
->extdev
));
3882 ddc
= aux
? &nv_connector
->aux
.ddc
: NULL
;
3883 type
= DRM_MODE_ENCODER_TMDS
;
3889 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
3892 nv_encoder
->dcb
= dcbe
;
3893 nv_encoder
->i2c
= ddc
;
3894 nv_encoder
->aux
= aux
;
3896 encoder
= to_drm_encoder(nv_encoder
);
3897 encoder
->possible_crtcs
= dcbe
->heads
;
3898 encoder
->possible_clones
= 0;
3899 drm_encoder_init(connector
->dev
, encoder
, &nv50_pior_func
, type
,
3900 "pior-%04x-%04x", dcbe
->hasht
, dcbe
->hashm
);
3901 drm_encoder_helper_add(encoder
, &nv50_pior_help
);
3903 drm_mode_connector_attach_encoder(connector
, encoder
);
3907 /******************************************************************************
3909 *****************************************************************************/
3912 nv50_disp_atomic_commit_core(struct nouveau_drm
*drm
, u32 interlock
)
3914 struct nv50_disp
*disp
= nv50_disp(drm
->dev
);
3915 struct nv50_dmac
*core
= &disp
->mast
.base
;
3916 struct nv50_mstm
*mstm
;
3917 struct drm_encoder
*encoder
;
3920 NV_ATOMIC(drm
, "commit core %08x\n", interlock
);
3922 drm_for_each_encoder(encoder
, drm
->dev
) {
3923 if (encoder
->encoder_type
!= DRM_MODE_ENCODER_DPMST
) {
3924 mstm
= nouveau_encoder(encoder
)->dp
.mstm
;
3925 if (mstm
&& mstm
->modified
)
3926 nv50_mstm_prepare(mstm
);
3930 if ((push
= evo_wait(core
, 5))) {
3931 evo_mthd(push
, 0x0084, 1);
3932 evo_data(push
, 0x80000000);
3933 evo_mthd(push
, 0x0080, 2);
3934 evo_data(push
, interlock
);
3935 evo_data(push
, 0x00000000);
3936 nouveau_bo_wr32(disp
->sync
, 0, 0x00000000);
3937 evo_kick(push
, core
);
3938 if (nvif_msec(&drm
->client
.device
, 2000ULL,
3939 if (nouveau_bo_rd32(disp
->sync
, 0))
3943 NV_ERROR(drm
, "EVO timeout\n");
3946 drm_for_each_encoder(encoder
, drm
->dev
) {
3947 if (encoder
->encoder_type
!= DRM_MODE_ENCODER_DPMST
) {
3948 mstm
= nouveau_encoder(encoder
)->dp
.mstm
;
3949 if (mstm
&& mstm
->modified
)
3950 nv50_mstm_cleanup(mstm
);
3956 nv50_disp_atomic_commit_tail(struct drm_atomic_state
*state
)
3958 struct drm_device
*dev
= state
->dev
;
3959 struct drm_crtc_state
*new_crtc_state
, *old_crtc_state
;
3960 struct drm_crtc
*crtc
;
3961 struct drm_plane_state
*new_plane_state
;
3962 struct drm_plane
*plane
;
3963 struct nouveau_drm
*drm
= nouveau_drm(dev
);
3964 struct nv50_disp
*disp
= nv50_disp(dev
);
3965 struct nv50_atom
*atom
= nv50_atom(state
);
3966 struct nv50_outp_atom
*outp
, *outt
;
3967 u32 interlock_core
= 0;
3968 u32 interlock_chan
= 0;
3971 NV_ATOMIC(drm
, "commit %d %d\n", atom
->lock_core
, atom
->flush_disable
);
3972 drm_atomic_helper_wait_for_fences(dev
, state
, false);
3973 drm_atomic_helper_wait_for_dependencies(state
);
3974 drm_atomic_helper_update_legacy_modeset_state(dev
, state
);
3976 if (atom
->lock_core
)
3977 mutex_lock(&disp
->mutex
);
3979 /* Disable head(s). */
3980 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
3981 struct nv50_head_atom
*asyh
= nv50_head_atom(new_crtc_state
);
3982 struct nv50_head
*head
= nv50_head(crtc
);
3984 NV_ATOMIC(drm
, "%s: clr %04x (set %04x)\n", crtc
->name
,
3985 asyh
->clr
.mask
, asyh
->set
.mask
);
3986 if (old_crtc_state
->active
&& !new_crtc_state
->active
)
3987 drm_crtc_vblank_off(crtc
);
3989 if (asyh
->clr
.mask
) {
3990 nv50_head_flush_clr(head
, asyh
, atom
->flush_disable
);
3991 interlock_core
|= 1;
3995 /* Disable plane(s). */
3996 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
) {
3997 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(new_plane_state
);
3998 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
4000 NV_ATOMIC(drm
, "%s: clr %02x (set %02x)\n", plane
->name
,
4001 asyw
->clr
.mask
, asyw
->set
.mask
);
4002 if (!asyw
->clr
.mask
)
4005 interlock_chan
|= nv50_wndw_flush_clr(wndw
, interlock_core
,
4006 atom
->flush_disable
,
4010 /* Disable output path(s). */
4011 list_for_each_entry(outp
, &atom
->outp
, head
) {
4012 const struct drm_encoder_helper_funcs
*help
;
4013 struct drm_encoder
*encoder
;
4015 encoder
= outp
->encoder
;
4016 help
= encoder
->helper_private
;
4018 NV_ATOMIC(drm
, "%s: clr %02x (set %02x)\n", encoder
->name
,
4019 outp
->clr
.mask
, outp
->set
.mask
);
4021 if (outp
->clr
.mask
) {
4022 help
->disable(encoder
);
4023 interlock_core
|= 1;
4024 if (outp
->flush_disable
) {
4025 nv50_disp_atomic_commit_core(drm
, interlock_chan
);
4032 /* Flush disable. */
4033 if (interlock_core
) {
4034 if (atom
->flush_disable
) {
4035 nv50_disp_atomic_commit_core(drm
, interlock_chan
);
4041 /* Update output path(s). */
4042 list_for_each_entry_safe(outp
, outt
, &atom
->outp
, head
) {
4043 const struct drm_encoder_helper_funcs
*help
;
4044 struct drm_encoder
*encoder
;
4046 encoder
= outp
->encoder
;
4047 help
= encoder
->helper_private
;
4049 NV_ATOMIC(drm
, "%s: set %02x (clr %02x)\n", encoder
->name
,
4050 outp
->set
.mask
, outp
->clr
.mask
);
4052 if (outp
->set
.mask
) {
4053 help
->enable(encoder
);
4057 list_del(&outp
->head
);
4061 /* Update head(s). */
4062 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
4063 struct nv50_head_atom
*asyh
= nv50_head_atom(new_crtc_state
);
4064 struct nv50_head
*head
= nv50_head(crtc
);
4066 NV_ATOMIC(drm
, "%s: set %04x (clr %04x)\n", crtc
->name
,
4067 asyh
->set
.mask
, asyh
->clr
.mask
);
4069 if (asyh
->set
.mask
) {
4070 nv50_head_flush_set(head
, asyh
);
4074 if (new_crtc_state
->active
) {
4075 if (!old_crtc_state
->active
)
4076 drm_crtc_vblank_on(crtc
);
4077 if (new_crtc_state
->event
)
4078 drm_crtc_vblank_get(crtc
);
4082 /* Update plane(s). */
4083 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
) {
4084 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(new_plane_state
);
4085 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
4087 NV_ATOMIC(drm
, "%s: set %02x (clr %02x)\n", plane
->name
,
4088 asyw
->set
.mask
, asyw
->clr
.mask
);
4089 if ( !asyw
->set
.mask
&&
4090 (!asyw
->clr
.mask
|| atom
->flush_disable
))
4093 interlock_chan
|= nv50_wndw_flush_set(wndw
, interlock_core
, asyw
);
4097 if (interlock_core
) {
4098 if (!interlock_chan
&& atom
->state
.legacy_cursor_update
) {
4099 u32
*push
= evo_wait(&disp
->mast
, 2);
4101 evo_mthd(push
, 0x0080, 1);
4102 evo_data(push
, 0x00000000);
4103 evo_kick(push
, &disp
->mast
);
4106 nv50_disp_atomic_commit_core(drm
, interlock_chan
);
4110 if (atom
->lock_core
)
4111 mutex_unlock(&disp
->mutex
);
4113 /* Wait for HW to signal completion. */
4114 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
) {
4115 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(new_plane_state
);
4116 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
4117 int ret
= nv50_wndw_wait_armed(wndw
, asyw
);
4119 NV_ERROR(drm
, "%s: timeout\n", plane
->name
);
4122 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
4123 if (new_crtc_state
->event
) {
4124 unsigned long flags
;
4125 /* Get correct count/ts if racing with vblank irq */
4126 if (new_crtc_state
->active
)
4127 drm_crtc_accurate_vblank_count(crtc
);
4128 spin_lock_irqsave(&crtc
->dev
->event_lock
, flags
);
4129 drm_crtc_send_vblank_event(crtc
, new_crtc_state
->event
);
4130 spin_unlock_irqrestore(&crtc
->dev
->event_lock
, flags
);
4132 new_crtc_state
->event
= NULL
;
4133 if (new_crtc_state
->active
)
4134 drm_crtc_vblank_put(crtc
);
4138 drm_atomic_helper_commit_hw_done(state
);
4139 drm_atomic_helper_cleanup_planes(dev
, state
);
4140 drm_atomic_helper_commit_cleanup_done(state
);
4141 drm_atomic_state_put(state
);
4145 nv50_disp_atomic_commit_work(struct work_struct
*work
)
4147 struct drm_atomic_state
*state
=
4148 container_of(work
, typeof(*state
), commit_work
);
4149 nv50_disp_atomic_commit_tail(state
);
4153 nv50_disp_atomic_commit(struct drm_device
*dev
,
4154 struct drm_atomic_state
*state
, bool nonblock
)
4156 struct nouveau_drm
*drm
= nouveau_drm(dev
);
4157 struct nv50_disp
*disp
= nv50_disp(dev
);
4158 struct drm_plane_state
*new_plane_state
;
4159 struct drm_plane
*plane
;
4160 struct drm_crtc
*crtc
;
4161 bool active
= false;
4164 ret
= pm_runtime_get_sync(dev
->dev
);
4165 if (ret
< 0 && ret
!= -EACCES
)
4168 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
4172 INIT_WORK(&state
->commit_work
, nv50_disp_atomic_commit_work
);
4174 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
4179 ret
= drm_atomic_helper_wait_for_fences(dev
, state
, true);
4184 ret
= drm_atomic_helper_swap_state(state
, true);
4188 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
) {
4189 struct nv50_wndw_atom
*asyw
= nv50_wndw_atom(new_plane_state
);
4190 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
4192 if (asyw
->set
.image
) {
4193 asyw
->ntfy
.handle
= wndw
->dmac
->sync
.handle
;
4194 asyw
->ntfy
.offset
= wndw
->ntfy
;
4195 asyw
->ntfy
.awaken
= false;
4196 asyw
->set
.ntfy
= true;
4197 nouveau_bo_wr32(disp
->sync
, wndw
->ntfy
/ 4, 0x00000000);
4202 drm_atomic_state_get(state
);
4205 queue_work(system_unbound_wq
, &state
->commit_work
);
4207 nv50_disp_atomic_commit_tail(state
);
4209 drm_for_each_crtc(crtc
, dev
) {
4210 if (crtc
->state
->enable
) {
4211 if (!drm
->have_disp_power_ref
) {
4212 drm
->have_disp_power_ref
= true;
4220 if (!active
&& drm
->have_disp_power_ref
) {
4221 pm_runtime_put_autosuspend(dev
->dev
);
4222 drm
->have_disp_power_ref
= false;
4227 drm_atomic_helper_cleanup_planes(dev
, state
);
4229 pm_runtime_put_autosuspend(dev
->dev
);
4233 static struct nv50_outp_atom
*
4234 nv50_disp_outp_atomic_add(struct nv50_atom
*atom
, struct drm_encoder
*encoder
)
4236 struct nv50_outp_atom
*outp
;
4238 list_for_each_entry(outp
, &atom
->outp
, head
) {
4239 if (outp
->encoder
== encoder
)
4243 outp
= kzalloc(sizeof(*outp
), GFP_KERNEL
);
4245 return ERR_PTR(-ENOMEM
);
4247 list_add(&outp
->head
, &atom
->outp
);
4248 outp
->encoder
= encoder
;
4253 nv50_disp_outp_atomic_check_clr(struct nv50_atom
*atom
,
4254 struct drm_connector_state
*old_connector_state
)
4256 struct drm_encoder
*encoder
= old_connector_state
->best_encoder
;
4257 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
4258 struct drm_crtc
*crtc
;
4259 struct nv50_outp_atom
*outp
;
4261 if (!(crtc
= old_connector_state
->crtc
))
4264 old_crtc_state
= drm_atomic_get_old_crtc_state(&atom
->state
, crtc
);
4265 new_crtc_state
= drm_atomic_get_new_crtc_state(&atom
->state
, crtc
);
4266 if (old_crtc_state
->active
&& drm_atomic_crtc_needs_modeset(new_crtc_state
)) {
4267 outp
= nv50_disp_outp_atomic_add(atom
, encoder
);
4269 return PTR_ERR(outp
);
4271 if (outp
->encoder
->encoder_type
== DRM_MODE_ENCODER_DPMST
) {
4272 outp
->flush_disable
= true;
4273 atom
->flush_disable
= true;
4275 outp
->clr
.ctrl
= true;
4276 atom
->lock_core
= true;
4283 nv50_disp_outp_atomic_check_set(struct nv50_atom
*atom
,
4284 struct drm_connector_state
*connector_state
)
4286 struct drm_encoder
*encoder
= connector_state
->best_encoder
;
4287 struct drm_crtc_state
*new_crtc_state
;
4288 struct drm_crtc
*crtc
;
4289 struct nv50_outp_atom
*outp
;
4291 if (!(crtc
= connector_state
->crtc
))
4294 new_crtc_state
= drm_atomic_get_new_crtc_state(&atom
->state
, crtc
);
4295 if (new_crtc_state
->active
&& drm_atomic_crtc_needs_modeset(new_crtc_state
)) {
4296 outp
= nv50_disp_outp_atomic_add(atom
, encoder
);
4298 return PTR_ERR(outp
);
4300 outp
->set
.ctrl
= true;
4301 atom
->lock_core
= true;
4308 nv50_disp_atomic_check(struct drm_device
*dev
, struct drm_atomic_state
*state
)
4310 struct nv50_atom
*atom
= nv50_atom(state
);
4311 struct drm_connector_state
*old_connector_state
, *new_connector_state
;
4312 struct drm_connector
*connector
;
4315 ret
= drm_atomic_helper_check(dev
, state
);
4319 for_each_oldnew_connector_in_state(state
, connector
, old_connector_state
, new_connector_state
, i
) {
4320 ret
= nv50_disp_outp_atomic_check_clr(atom
, old_connector_state
);
4324 ret
= nv50_disp_outp_atomic_check_set(atom
, new_connector_state
);
4333 nv50_disp_atomic_state_clear(struct drm_atomic_state
*state
)
4335 struct nv50_atom
*atom
= nv50_atom(state
);
4336 struct nv50_outp_atom
*outp
, *outt
;
4338 list_for_each_entry_safe(outp
, outt
, &atom
->outp
, head
) {
4339 list_del(&outp
->head
);
4343 drm_atomic_state_default_clear(state
);
4347 nv50_disp_atomic_state_free(struct drm_atomic_state
*state
)
4349 struct nv50_atom
*atom
= nv50_atom(state
);
4350 drm_atomic_state_default_release(&atom
->state
);
4354 static struct drm_atomic_state
*
4355 nv50_disp_atomic_state_alloc(struct drm_device
*dev
)
4357 struct nv50_atom
*atom
;
4358 if (!(atom
= kzalloc(sizeof(*atom
), GFP_KERNEL
)) ||
4359 drm_atomic_state_init(dev
, &atom
->state
) < 0) {
4363 INIT_LIST_HEAD(&atom
->outp
);
4364 return &atom
->state
;
4367 static const struct drm_mode_config_funcs
4369 .fb_create
= nouveau_user_framebuffer_create
,
4370 .output_poll_changed
= drm_fb_helper_output_poll_changed
,
4371 .atomic_check
= nv50_disp_atomic_check
,
4372 .atomic_commit
= nv50_disp_atomic_commit
,
4373 .atomic_state_alloc
= nv50_disp_atomic_state_alloc
,
4374 .atomic_state_clear
= nv50_disp_atomic_state_clear
,
4375 .atomic_state_free
= nv50_disp_atomic_state_free
,
4378 /******************************************************************************
4380 *****************************************************************************/
4383 nv50_display_fini(struct drm_device
*dev
)
4385 struct nouveau_encoder
*nv_encoder
;
4386 struct drm_encoder
*encoder
;
4387 struct drm_plane
*plane
;
4389 drm_for_each_plane(plane
, dev
) {
4390 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
4391 if (plane
->funcs
!= &nv50_wndw
)
4393 nv50_wndw_fini(wndw
);
4396 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
4397 if (encoder
->encoder_type
!= DRM_MODE_ENCODER_DPMST
) {
4398 nv_encoder
= nouveau_encoder(encoder
);
4399 nv50_mstm_fini(nv_encoder
->dp
.mstm
);
4405 nv50_display_init(struct drm_device
*dev
)
4407 struct drm_encoder
*encoder
;
4408 struct drm_plane
*plane
;
4411 push
= evo_wait(nv50_mast(dev
), 32);
4415 evo_mthd(push
, 0x0088, 1);
4416 evo_data(push
, nv50_mast(dev
)->base
.sync
.handle
);
4417 evo_kick(push
, nv50_mast(dev
));
4419 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
) {
4420 if (encoder
->encoder_type
!= DRM_MODE_ENCODER_DPMST
) {
4421 struct nouveau_encoder
*nv_encoder
=
4422 nouveau_encoder(encoder
);
4423 nv50_mstm_init(nv_encoder
->dp
.mstm
);
4427 drm_for_each_plane(plane
, dev
) {
4428 struct nv50_wndw
*wndw
= nv50_wndw(plane
);
4429 if (plane
->funcs
!= &nv50_wndw
)
4431 nv50_wndw_init(wndw
);
4438 nv50_display_destroy(struct drm_device
*dev
)
4440 struct nv50_disp
*disp
= nv50_disp(dev
);
4442 nv50_dmac_destroy(&disp
->mast
.base
, disp
->disp
);
4444 nouveau_bo_unmap(disp
->sync
);
4446 nouveau_bo_unpin(disp
->sync
);
4447 nouveau_bo_ref(NULL
, &disp
->sync
);
4449 nouveau_display(dev
)->priv
= NULL
;
4453 MODULE_PARM_DESC(atomic
, "Expose atomic ioctl (default: disabled)");
4454 static int nouveau_atomic
= 0;
4455 module_param_named(atomic
, nouveau_atomic
, int, 0400);
4458 nv50_display_create(struct drm_device
*dev
)
4460 struct nvif_device
*device
= &nouveau_drm(dev
)->client
.device
;
4461 struct nouveau_drm
*drm
= nouveau_drm(dev
);
4462 struct dcb_table
*dcb
= &drm
->vbios
.dcb
;
4463 struct drm_connector
*connector
, *tmp
;
4464 struct nv50_disp
*disp
;
4465 struct dcb_output
*dcbe
;
4468 disp
= kzalloc(sizeof(*disp
), GFP_KERNEL
);
4472 mutex_init(&disp
->mutex
);
4474 nouveau_display(dev
)->priv
= disp
;
4475 nouveau_display(dev
)->dtor
= nv50_display_destroy
;
4476 nouveau_display(dev
)->init
= nv50_display_init
;
4477 nouveau_display(dev
)->fini
= nv50_display_fini
;
4478 disp
->disp
= &nouveau_display(dev
)->disp
;
4479 dev
->mode_config
.funcs
= &nv50_disp_func
;
4480 dev
->driver
->driver_features
|= DRIVER_PREFER_XBGR_30BPP
;
4482 dev
->driver
->driver_features
|= DRIVER_ATOMIC
;
4484 /* small shared memory area we use for notifiers and semaphores */
4485 ret
= nouveau_bo_new(&drm
->client
, 4096, 0x1000, TTM_PL_FLAG_VRAM
,
4486 0, 0x0000, NULL
, NULL
, &disp
->sync
);
4488 ret
= nouveau_bo_pin(disp
->sync
, TTM_PL_FLAG_VRAM
, true);
4490 ret
= nouveau_bo_map(disp
->sync
);
4492 nouveau_bo_unpin(disp
->sync
);
4495 nouveau_bo_ref(NULL
, &disp
->sync
);
4501 /* allocate master evo channel */
4502 ret
= nv50_core_create(device
, disp
->disp
, disp
->sync
->bo
.offset
,
4507 /* create crtc objects to represent the hw heads */
4508 if (disp
->disp
->oclass
>= GF110_DISP
)
4509 crtcs
= nvif_rd32(&device
->object
, 0x612004) & 0xf;
4513 for (i
= 0; i
< fls(crtcs
); i
++) {
4514 if (!(crtcs
& (1 << i
)))
4516 ret
= nv50_head_create(dev
, i
);
4521 /* create encoder/connector objects based on VBIOS DCB table */
4522 for (i
= 0, dcbe
= &dcb
->entry
[0]; i
< dcb
->entries
; i
++, dcbe
++) {
4523 connector
= nouveau_connector_create(dev
, dcbe
->connector
);
4524 if (IS_ERR(connector
))
4527 if (dcbe
->location
== DCB_LOC_ON_CHIP
) {
4528 switch (dcbe
->type
) {
4529 case DCB_OUTPUT_TMDS
:
4530 case DCB_OUTPUT_LVDS
:
4532 ret
= nv50_sor_create(connector
, dcbe
);
4534 case DCB_OUTPUT_ANALOG
:
4535 ret
= nv50_dac_create(connector
, dcbe
);
4542 ret
= nv50_pior_create(connector
, dcbe
);
4546 NV_WARN(drm
, "failed to create encoder %d/%d/%d: %d\n",
4547 dcbe
->location
, dcbe
->type
,
4548 ffs(dcbe
->or) - 1, ret
);
4553 /* cull any connectors we created that don't have an encoder */
4554 list_for_each_entry_safe(connector
, tmp
, &dev
->mode_config
.connector_list
, head
) {
4555 if (connector
->encoder_ids
[0])
4558 NV_WARN(drm
, "%s has no encoders, removing\n",
4560 connector
->funcs
->destroy(connector
);
4565 nv50_display_destroy(dev
);