]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - drivers/gpu/drm/nouveau/nv50_display.c
drm: Nuke fb->pixel_format
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / nouveau / nv50_display.c
index 90fe9e0334aa4b8150e45a700d8ef4cc63166f71..cb85cb72dc1c30cb5114a3f31ecaf3b508e5aa22 100644 (file)
@@ -418,12 +418,12 @@ nv50_dmac_ctxdma_del(struct nv50_dmac_ctxdma *ctxdma)
 }
 
 static struct nv50_dmac_ctxdma *
-nv50_dmac_ctxdma_new(struct nv50_dmac *dmac, u32 handle,
-                    struct nouveau_framebuffer *fb)
+nv50_dmac_ctxdma_new(struct nv50_dmac *dmac, struct nouveau_framebuffer *fb)
 {
        struct nouveau_drm *drm = nouveau_drm(fb->base.dev);
        struct nv50_dmac_ctxdma *ctxdma;
-       const u8  kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8;
+       const u8    kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8;
+       const u32 handle = 0xfb000000 | kind;
        struct {
                struct nv_dma_v0 base;
                union {
@@ -574,7 +574,7 @@ nv50_core_create(struct nvif_device *device, struct nvif_object *disp,
                .pushbuf = 0xb0007d00,
        };
        static const s32 oclass[] = {
-               GP104_DISP_CORE_CHANNEL_DMA,
+               GP102_DISP_CORE_CHANNEL_DMA,
                GP100_DISP_CORE_CHANNEL_DMA,
                GM200_DISP_CORE_CHANNEL_DMA,
                GM107_DISP_CORE_CHANNEL_DMA,
@@ -658,15 +658,8 @@ nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp,
 
 struct nv50_head {
        struct nouveau_crtc base;
-       struct nouveau_bo *image;
        struct nv50_ovly ovly;
        struct nv50_oimm oimm;
-
-       struct nv50_head_atom arm;
-       struct nv50_head_atom asy;
-
-       struct nv50_base *_base;
-       struct nv50_curs *_curs;
 };
 
 #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
@@ -692,12 +685,6 @@ nv50_disp(struct drm_device *dev)
 
 #define nv50_mast(d) (&nv50_disp(d)->mast)
 
-static struct drm_crtc *
-nv50_display_crtc_get(struct drm_encoder *encoder)
-{
-       return nouveau_encoder(encoder)->crtc;
-}
-
 /******************************************************************************
  * EVO channel helpers
  *****************************************************************************/
@@ -750,40 +737,6 @@ evo_kick(u32 *push, void *evoc)
        *((p)++) = _d;                                                         \
 } while(0)
 
-static bool
-evo_sync_wait(void *data)
-{
-       if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
-               return true;
-       usleep_range(1, 2);
-       return false;
-}
-
-static int
-evo_sync(struct drm_device *dev)
-{
-       struct nvif_device *device = &nouveau_drm(dev)->device;
-       struct nv50_disp *disp = nv50_disp(dev);
-       struct nv50_mast *mast = nv50_mast(dev);
-       u32 *push = evo_wait(mast, 8);
-       if (push) {
-               nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
-               evo_mthd(push, 0x0084, 1);
-               evo_data(push, 0x80000000 | EVO_MAST_NTFY);
-               evo_mthd(push, 0x0080, 2);
-               evo_data(push, 0x00000000);
-               evo_data(push, 0x00000000);
-               evo_kick(push, mast);
-               if (nvif_msec(device, 2000,
-                       if (evo_sync_wait(disp->sync))
-                               break;
-               ) >= 0)
-                       return 0;
-       }
-
-       return -EBUSY;
-}
-
 /******************************************************************************
  * Plane
  *****************************************************************************/
@@ -799,8 +752,6 @@ struct nv50_wndw {
        u16 ntfy;
        u16 sema;
        u32 data;
-
-       struct nv50_wndw_atom asy;
 };
 
 struct nv50_wndw_func {
@@ -1000,21 +951,17 @@ nv50_wndw_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state)
        struct nv50_wndw_atom *asyw = nv50_wndw_atom(state);
        struct nv50_head_atom *asyh;
        struct nv50_dmac_ctxdma *ctxdma;
-       u32 name;
-       u8 kind;
        int ret;
 
        NV_ATOMIC(drm, "%s prepare: %p\n", plane->name, state->fb);
        if (!asyw->state.fb)
                return 0;
-       kind = (fb->nvbo->tile_flags & 0x0000ff00) >> 8;
-       name = 0xfb000000 | kind;
 
        ret = nouveau_bo_pin(fb->nvbo, TTM_PL_FLAG_VRAM, true);
        if (ret)
                return ret;
 
-       ctxdma = nv50_dmac_ctxdma_new(wndw->dmac, name, fb);
+       ctxdma = nv50_dmac_ctxdma_new(wndw->dmac, fb);
        if (IS_ERR(ctxdma)) {
                nouveau_bo_unpin(fb->nvbo);
                return PTR_ERR(ctxdma);
@@ -1206,7 +1153,7 @@ nv50_curs_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
        if (asyw->state.fb->width != asyw->state.fb->height)
                return -EINVAL;
 
-       switch (asyw->state.fb->pixel_format) {
+       switch (asyw->state.fb->format->format) {
        case DRM_FORMAT_ARGB8888: asyh->curs.format = 1; break;
        default:
                WARN_ON(1);
@@ -1471,12 +1418,10 @@ static int
 nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
                  struct nv50_head_atom *asyh)
 {
-       const u32 format = asyw->state.fb->pixel_format;
-       const struct drm_format_info *info;
+       const struct drm_framebuffer *fb = asyw->state.fb;
        int ret;
 
-       info = drm_format_info(format);
-       if (!info || !info->depth)
+       if (!fb->format->depth)
                return -EINVAL;
 
        ret = drm_plane_helper_check_state(&asyw->state, &asyw->clip,
@@ -1486,14 +1431,14 @@ nv50_base_acquire(struct nv50_wndw *wndw, struct nv50_wndw_atom *asyw,
        if (ret)
                return ret;
 
-       asyh->base.depth = info->depth;
-       asyh->base.cpp = info->cpp[0];
+       asyh->base.depth = fb->format->depth;
+       asyh->base.cpp = fb->format->cpp[0];
        asyh->base.x = asyw->state.src.x1 >> 16;
        asyh->base.y = asyw->state.src.y1 >> 16;
        asyh->base.w = asyw->state.fb->width;
        asyh->base.h = asyw->state.fb->height;
 
-       switch (format) {
+       switch (fb->format->format) {
        case DRM_FORMAT_C8         : asyw->image.format = 0x1e; break;
        case DRM_FORMAT_RGB565     : asyw->image.format = 0xe8; break;
        case DRM_FORMAT_XRGB1555   :
@@ -1591,151 +1536,6 @@ nv50_base_new(struct nouveau_drm *drm, struct nv50_head *head,
                                &base->wndw.notify);
 }
 
-/******************************************************************************
- * Page flipping channel
- *****************************************************************************/
-struct nouveau_bo *
-nv50_display_crtc_sema(struct drm_device *dev, int crtc)
-{
-       return nv50_disp(dev)->sync;
-}
-
-struct nv50_display_flip {
-       struct nv50_disp *disp;
-       struct nv50_base *base;
-};
-
-static bool
-nv50_display_flip_wait(void *data)
-{
-       struct nv50_display_flip *flip = data;
-       if (nouveau_bo_rd32(flip->disp->sync, flip->base->wndw.sema / 4) ==
-                                             flip->base->wndw.data)
-               return true;
-       usleep_range(1, 2);
-       return false;
-}
-
-void
-nv50_display_flip_stop(struct drm_crtc *crtc)
-{
-       struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
-       struct nv50_base *base = nv50_head(crtc)->_base;
-       struct nv50_wndw *wndw = &base->wndw;
-       struct nv50_wndw_atom *asyw = &wndw->asy;
-       struct nv50_display_flip flip = {
-               .disp = nv50_disp(crtc->dev),
-               .base = base,
-       };
-
-       asyw->state.crtc = NULL;
-       asyw->state.fb = NULL;
-       nv50_wndw_atomic_check(&wndw->plane, &asyw->state);
-       nv50_wndw_flush_clr(wndw, 0, true, asyw);
-
-       nvif_msec(device, 2000,
-               if (nv50_display_flip_wait(&flip))
-                       break;
-       );
-}
-
-int
-nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
-                      struct nouveau_channel *chan, u32 swap_interval)
-{
-       struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       struct nv50_head *head = nv50_head(crtc);
-       struct nv50_base *base = nv50_head(crtc)->_base;
-       struct nv50_wndw *wndw = &base->wndw;
-       struct nv50_wndw_atom *asyw = &wndw->asy;
-       int ret;
-
-       if (crtc->primary->fb->width != fb->width ||
-           crtc->primary->fb->height != fb->height)
-               return -EINVAL;
-
-       if (chan == NULL)
-               evo_sync(crtc->dev);
-
-       if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) {
-               ret = RING_SPACE(chan, 8);
-               if (ret)
-                       return ret;
-
-               BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
-               OUT_RING  (chan, NvEvoSema0 + nv_crtc->index);
-               OUT_RING  (chan, base->wndw.sema ^ 0x10);
-               BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
-               OUT_RING  (chan, base->wndw.data + 1);
-               BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
-               OUT_RING  (chan, base->wndw.sema);
-               OUT_RING  (chan, base->wndw.data);
-       } else
-       if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) {
-               u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + base->wndw.sema;
-               ret = RING_SPACE(chan, 12);
-               if (ret)
-                       return ret;
-
-               BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
-               OUT_RING  (chan, chan->vram.handle);
-               BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
-               OUT_RING  (chan, upper_32_bits(addr ^ 0x10));
-               OUT_RING  (chan, lower_32_bits(addr ^ 0x10));
-               OUT_RING  (chan, base->wndw.data + 1);
-               OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
-               BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
-               OUT_RING  (chan, upper_32_bits(addr));
-               OUT_RING  (chan, lower_32_bits(addr));
-               OUT_RING  (chan, base->wndw.data);
-               OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
-       } else
-       if (chan) {
-               u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + base->wndw.sema;
-               ret = RING_SPACE(chan, 10);
-               if (ret)
-                       return ret;
-
-               BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
-               OUT_RING  (chan, upper_32_bits(addr ^ 0x10));
-               OUT_RING  (chan, lower_32_bits(addr ^ 0x10));
-               OUT_RING  (chan, base->wndw.data + 1);
-               OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
-                                NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
-               BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
-               OUT_RING  (chan, upper_32_bits(addr));
-               OUT_RING  (chan, lower_32_bits(addr));
-               OUT_RING  (chan, base->wndw.data);
-               OUT_RING  (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
-                                NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
-       }
-
-       if (chan) {
-               base->wndw.sema ^= 0x10;
-               base->wndw.data++;
-               FIRE_RING (chan);
-       }
-
-       /* queue the flip */
-       asyw->state.crtc = &head->base.base;
-       asyw->state.fb = fb;
-       asyw->interval = swap_interval;
-       asyw->image.handle = nv_fb->r_handle;
-       asyw->image.offset = nv_fb->nvbo->bo.offset;
-       asyw->sema.handle = base->chan.base.sync.handle;
-       asyw->sema.offset = base->wndw.sema;
-       asyw->sema.acquire = base->wndw.data++;
-       asyw->sema.release = base->wndw.data;
-       nv50_wndw_atomic_check(&wndw->plane, &asyw->state);
-       asyw->set.sema = true;
-       nv50_wndw_flush_set(wndw, 0, asyw);
-       nv50_wndw_wait_armed(wndw, asyw);
-
-       nouveau_bo_ref(nv_fb->nvbo, &head->image);
-       return 0;
-}
-
 /******************************************************************************
  * Head
  *****************************************************************************/
@@ -1924,6 +1724,11 @@ nv50_head_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
                        evo_data(push, asyh->core.handle);
                        evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1);
                        evo_data(push, (asyh->core.y << 16) | asyh->core.x);
+                       /* EVO will complain with INVALID_STATE if we have an
+                        * active cursor and (re)specify HeadSetContextDmaIso
+                        * without also updating HeadSetOffsetCursor.
+                        */
+                       asyh->set.curs = asyh->curs.visible;
                } else
                if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
                        evo_mthd(push, 0x0860 + head->base.index * 0x400, 1);
@@ -2373,1022 +2178,1131 @@ nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_crtc_state *state)
        return 0;
 }
 
-/******************************************************************************
- * CRTC
- *****************************************************************************/
-
-static int
-nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
+static void
+nv50_head_lut_load(struct drm_crtc *crtc)
 {
-       struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
-       struct nv50_head *head = nv50_head(&nv_crtc->base);
-       struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state);
-       struct nouveau_connector *nv_connector;
-       struct nouveau_conn_atom asyc;
-       u32 *push;
-
-       nv_connector = nouveau_crtc_connector_get(nv_crtc);
+       struct nv50_disp *disp = nv50_disp(crtc->dev);
+       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
+       void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
+       int i;
 
-       asyc.state.connector = &nv_connector->base;
-       asyc.dither.mode = nv_connector->dithering_mode;
-       asyc.dither.depth = nv_connector->dithering_depth;
-       asyh->state.crtc = &nv_crtc->base;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_atomic_check_dither(&head->arm, asyh, &asyc);
-       nv50_head_flush_set(head, asyh);
+       for (i = 0; i < 256; i++) {
+               u16 r = nv_crtc->lut.r[i] >> 2;
+               u16 g = nv_crtc->lut.g[i] >> 2;
+               u16 b = nv_crtc->lut.b[i] >> 2;
 
-       if (update) {
-               if ((push = evo_wait(mast, 2))) {
-                       evo_mthd(push, 0x0080, 1);
-                       evo_data(push, 0x00000000);
-                       evo_kick(push, mast);
+               if (disp->disp->oclass < GF110_DISP) {
+                       writew(r + 0x0000, lut + (i * 0x08) + 0);
+                       writew(g + 0x0000, lut + (i * 0x08) + 2);
+                       writew(b + 0x0000, lut + (i * 0x08) + 4);
+               } else {
+                       writew(r + 0x6000, lut + (i * 0x20) + 0);
+                       writew(g + 0x6000, lut + (i * 0x20) + 2);
+                       writew(b + 0x6000, lut + (i * 0x20) + 4);
                }
        }
-
-       return 0;
 }
 
 static int
-nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
+nv50_head_mode_set_base_atomic(struct drm_crtc *crtc,
+                              struct drm_framebuffer *fb, int x, int y,
+                              enum mode_set_atomic state)
 {
-       struct nv50_head *head = nv50_head(&nv_crtc->base);
-       struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state);
-       struct drm_crtc *crtc = &nv_crtc->base;
-       struct nouveau_connector *nv_connector;
-       struct nouveau_conn_atom asyc;
-
-       nv_connector = nouveau_crtc_connector_get(nv_crtc);
-
-       asyc.state.connector = &nv_connector->base;
-       asyc.scaler.mode = nv_connector->scaling_mode;
-       asyc.scaler.full = nv_connector->scaling_full;
-       asyc.scaler.underscan.mode = nv_connector->underscan;
-       asyc.scaler.underscan.hborder = nv_connector->underscan_hborder;
-       asyc.scaler.underscan.vborder = nv_connector->underscan_vborder;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_atomic_check_view(&head->arm, asyh, &asyc);
-       nv50_head_flush_set(head, asyh);
-
-       if (update) {
-               nv50_display_flip_stop(crtc);
-               nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
-       }
-
+       WARN_ON(1);
        return 0;
 }
 
+static const struct drm_crtc_helper_funcs
+nv50_head_help = {
+       .mode_set_base_atomic = nv50_head_mode_set_base_atomic,
+       .load_lut = nv50_head_lut_load,
+       .atomic_check = nv50_head_atomic_check,
+};
+
+/* This is identical to the version in the atomic helpers, except that
+ * it supports non-vblanked ("async") page flips.
+ */
 static int
-nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
+nv50_head_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
+                   struct drm_pending_vblank_event *event, u32 flags)
 {
-       struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
-       struct nv50_head *head = nv50_head(&nv_crtc->base);
-       struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state);
-       struct nouveau_conn_atom asyc;
-       u32 *push;
+       struct drm_plane *plane = crtc->primary;
+       struct drm_atomic_state *state;
+       struct drm_plane_state *plane_state;
+       struct drm_crtc_state *crtc_state;
+       int ret = 0;
 
-       asyc.procamp.color_vibrance = nv_crtc->color_vibrance + 100;
-       asyc.procamp.vibrant_hue = nv_crtc->vibrant_hue + 90;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_atomic_check_procamp(&head->arm, asyh, &asyc);
-       nv50_head_flush_set(head, asyh);
+       state = drm_atomic_state_alloc(plane->dev);
+       if (!state)
+               return -ENOMEM;
 
-       if (update) {
-               if ((push = evo_wait(mast, 2))) {
-                       evo_mthd(push, 0x0080, 1);
-                       evo_data(push, 0x00000000);
-                       evo_kick(push, mast);
-               }
+       state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
+retry:
+       crtc_state = drm_atomic_get_crtc_state(state, crtc);
+       if (IS_ERR(crtc_state)) {
+               ret = PTR_ERR(crtc_state);
+               goto fail;
        }
+       crtc_state->event = event;
 
-       return 0;
-}
-
-static int
-nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
-                   int x, int y, bool update)
-{
-       struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
-       struct nv50_head *head = nv50_head(&nv_crtc->base);
-       struct nv50_head_atom *asyh = &head->asy;
-       struct nv50_wndw_atom *asyw = &head->_base->wndw.asy;
-       const struct drm_format_info *info;
+       plane_state = drm_atomic_get_plane_state(state, plane);
+       if (IS_ERR(plane_state)) {
+               ret = PTR_ERR(plane_state);
+               goto fail;
+       }
 
-       info = drm_format_info(nvfb->base.pixel_format);
-       if (!info || !info->depth)
-               return -EINVAL;
+       ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
+       if (ret != 0)
+               goto fail;
+       drm_atomic_set_fb_for_plane(plane_state, fb);
 
-       asyh->base.depth = info->depth;
-       asyh->base.cpp = info->cpp[0];
-       asyh->base.x = x;
-       asyh->base.y = y;
-       asyh->base.w = nvfb->base.width;
-       asyh->base.h = nvfb->base.height;
-       asyw->state.src_x = x << 16;
-       asyw->state.src_y = y << 16;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_flush_set(head, asyh);
-
-       if (update) {
-               struct nv50_mast *core = nv50_mast(nv_crtc->base.dev);
-               u32 *push = evo_wait(core, 2);
-               if (push) {
-                       evo_mthd(push, 0x0080, 1);
-                       evo_data(push, 0x00000000);
-                       evo_kick(push, core);
-               }
+       /* Make sure we don't accidentally do a full modeset. */
+       state->allow_modeset = false;
+       if (!crtc_state->active) {
+               DRM_DEBUG_ATOMIC("[CRTC:%d] disabled, rejecting legacy flip\n",
+                                crtc->base.id);
+               ret = -EINVAL;
+               goto fail;
        }
 
-       nv_crtc->fb.handle = nvfb->r_handle;
-       return 0;
-}
+       if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
+               nv50_wndw_atom(plane_state)->interval = 0;
 
-static void
-nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
-{
-       struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
-       struct nv50_head *head = nv50_head(&nv_crtc->base);
-       struct nv50_head_atom *asyh = &head->asy;
+       ret = drm_atomic_nonblocking_commit(state);
+fail:
+       if (ret == -EDEADLK)
+               goto backoff;
+
+       drm_atomic_state_put(state);
+       return ret;
+
+backoff:
+       drm_atomic_state_clear(state);
+       drm_atomic_legacy_backoff(state);
+
+       /*
+        * Someone might have exchanged the framebuffer while we dropped locks
+        * in the backoff code. We need to fix up the fb refcount tracking the
+        * core does for us.
+        */
+       plane->old_fb = plane->fb;
 
-       asyh->curs.visible = true;
-       asyh->curs.handle = mast->base.vram.handle;
-       asyh->curs.offset = nv_crtc->cursor.nvbo->bo.offset;
-       asyh->curs.layout = 1;
-       asyh->curs.format = 1;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_flush_set(head, asyh);
+       goto retry;
 }
 
-static void
-nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
+static int
+nv50_head_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
+                   uint32_t size)
 {
-       struct nv50_head *head = nv50_head(&nv_crtc->base);
-       struct nv50_head_atom *asyh = &head->asy;
+       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
+       u32 i;
 
-       asyh->curs.visible = false;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_flush_clr(head, asyh, false);
+       for (i = 0; i < size; i++) {
+               nv_crtc->lut.r[i] = r[i];
+               nv_crtc->lut.g[i] = g[i];
+               nv_crtc->lut.b[i] = b[i];
+       }
+
+       nv50_head_lut_load(crtc);
+       return 0;
 }
 
 static void
-nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
+nv50_head_atomic_destroy_state(struct drm_crtc *crtc,
+                              struct drm_crtc_state *state)
 {
-       struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
-
-       if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
-               nv50_crtc_cursor_show(nv_crtc);
-       else
-               nv50_crtc_cursor_hide(nv_crtc);
+       struct nv50_head_atom *asyh = nv50_head_atom(state);
+       __drm_atomic_helper_crtc_destroy_state(&asyh->state);
+       kfree(asyh);
+}
 
-       if (update) {
-               u32 *push = evo_wait(mast, 2);
-               if (push) {
-                       evo_mthd(push, 0x0080, 1);
-                       evo_data(push, 0x00000000);
-                       evo_kick(push, mast);
-               }
-       }
+static struct drm_crtc_state *
+nv50_head_atomic_duplicate_state(struct drm_crtc *crtc)
+{
+       struct nv50_head_atom *armh = nv50_head_atom(crtc->state);
+       struct nv50_head_atom *asyh;
+       if (!(asyh = kmalloc(sizeof(*asyh), GFP_KERNEL)))
+               return NULL;
+       __drm_atomic_helper_crtc_duplicate_state(crtc, &asyh->state);
+       asyh->view = armh->view;
+       asyh->mode = armh->mode;
+       asyh->lut  = armh->lut;
+       asyh->core = armh->core;
+       asyh->curs = armh->curs;
+       asyh->base = armh->base;
+       asyh->ovly = armh->ovly;
+       asyh->dither = armh->dither;
+       asyh->procamp = armh->procamp;
+       asyh->clr.mask = 0;
+       asyh->set.mask = 0;
+       return &asyh->state;
 }
 
 static void
-nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
+__drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
+                              struct drm_crtc_state *state)
 {
+       if (crtc->state)
+               crtc->funcs->atomic_destroy_state(crtc, crtc->state);
+       crtc->state = state;
+       crtc->state->crtc = crtc;
 }
 
 static void
-nv50_crtc_prepare(struct drm_crtc *crtc)
+nv50_head_reset(struct drm_crtc *crtc)
 {
-       struct nv50_head *head = nv50_head(crtc);
-       struct nv50_head_atom *asyh = &head->asy;
+       struct nv50_head_atom *asyh;
 
-       nv50_display_flip_stop(crtc);
+       if (WARN_ON(!(asyh = kzalloc(sizeof(*asyh), GFP_KERNEL))))
+               return;
 
-       asyh->state.active = false;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_flush_clr(head, asyh, false);
+       __drm_atomic_helper_crtc_reset(crtc, &asyh->state);
 }
 
 static void
-nv50_crtc_commit(struct drm_crtc *crtc)
+nv50_head_destroy(struct drm_crtc *crtc)
 {
+       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
+       struct nv50_disp *disp = nv50_disp(crtc->dev);
        struct nv50_head *head = nv50_head(crtc);
-       struct nv50_head_atom *asyh = &head->asy;
 
-       asyh->state.active = true;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
-       nv50_head_flush_set(head, asyh);
+       nv50_dmac_destroy(&head->ovly.base, disp->disp);
+       nv50_pioc_destroy(&head->oimm.base);
 
-       nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
-}
+       nouveau_bo_unmap(nv_crtc->lut.nvbo);
+       if (nv_crtc->lut.nvbo)
+               nouveau_bo_unpin(nv_crtc->lut.nvbo);
+       nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
 
-static bool
-nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
-                    struct drm_display_mode *adjusted_mode)
-{
-       drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
-       return true;
+       drm_crtc_cleanup(crtc);
+       kfree(crtc);
 }
 
-static int
-nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
-{
-       struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
-       struct nv50_head *head = nv50_head(crtc);
-       int ret;
+static const struct drm_crtc_funcs
+nv50_head_func = {
+       .reset = nv50_head_reset,
+       .gamma_set = nv50_head_gamma_set,
+       .destroy = nv50_head_destroy,
+       .set_config = drm_atomic_helper_set_config,
+       .page_flip = nv50_head_page_flip,
+       .set_property = drm_atomic_helper_crtc_set_property,
+       .atomic_duplicate_state = nv50_head_atomic_duplicate_state,
+       .atomic_destroy_state = nv50_head_atomic_destroy_state,
+};
+
+static int
+nv50_head_create(struct drm_device *dev, int index)
+{
+       struct nouveau_drm *drm = nouveau_drm(dev);
+       struct nvif_device *device = &drm->device;
+       struct nv50_disp *disp = nv50_disp(dev);
+       struct nv50_head *head;
+       struct nv50_base *base;
+       struct nv50_curs *curs;
+       struct drm_crtc *crtc;
+       int ret, i;
+
+       head = kzalloc(sizeof(*head), GFP_KERNEL);
+       if (!head)
+               return -ENOMEM;
 
-       ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
-       if (ret == 0) {
-               if (head->image)
-                       nouveau_bo_unpin(head->image);
-               nouveau_bo_ref(nvfb->nvbo, &head->image);
+       head->base.index = index;
+       for (i = 0; i < 256; i++) {
+               head->base.lut.r[i] = i << 8;
+               head->base.lut.g[i] = i << 8;
+               head->base.lut.b[i] = i << 8;
        }
 
-       return ret;
-}
+       ret = nv50_base_new(drm, head, &base);
+       if (ret == 0)
+               ret = nv50_curs_new(drm, head, &curs);
+       if (ret) {
+               kfree(head);
+               return ret;
+       }
 
-static int
-nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
-                  struct drm_display_mode *mode, int x, int y,
-                  struct drm_framebuffer *old_fb)
-{
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       struct nouveau_connector *nv_connector;
-       int ret;
-       struct nv50_head *head = nv50_head(crtc);
-       struct nv50_head_atom *asyh = &head->asy;
+       crtc = &head->base.base;
+       drm_crtc_init_with_planes(dev, crtc, &base->wndw.plane,
+                                 &curs->wndw.plane, &nv50_head_func,
+                                 "head-%d", head->base.index);
+       drm_crtc_helper_add(crtc, &nv50_head_help);
+       drm_mode_crtc_set_gamma_size(crtc, 256);
 
-       memcpy(&asyh->state.mode, umode, sizeof(*umode));
-       memcpy(&asyh->state.adjusted_mode, mode, sizeof(*mode));
-       asyh->state.active = true;
-       asyh->state.mode_changed = true;
-       nv50_head_atomic_check(&head->base.base, &asyh->state);
+       ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
+                            0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
+       if (!ret) {
+               ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
+               if (!ret) {
+                       ret = nouveau_bo_map(head->base.lut.nvbo);
+                       if (ret)
+                               nouveau_bo_unpin(head->base.lut.nvbo);
+               }
+               if (ret)
+                       nouveau_bo_ref(NULL, &head->base.lut.nvbo);
+       }
 
-       ret = nv50_crtc_swap_fbs(crtc, old_fb);
        if (ret)
-               return ret;
+               goto out;
 
-       nv50_head_flush_set(head, asyh);
+       /* allocate overlay resources */
+       ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
+       if (ret)
+               goto out;
 
-       nv_connector = nouveau_crtc_connector_get(nv_crtc);
-       nv50_crtc_set_dither(nv_crtc, false);
-       nv50_crtc_set_scale(nv_crtc, false);
+       ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
+                              &head->ovly);
+       if (ret)
+               goto out;
 
-       nv50_crtc_set_color_vibrance(nv_crtc, false);
-       nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
-       return 0;
+out:
+       if (ret)
+               nv50_head_destroy(crtc);
+       return ret;
 }
 
+/******************************************************************************
+ * Output path helpers
+ *****************************************************************************/
 static int
-nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
-                       struct drm_framebuffer *old_fb)
+nv50_outp_atomic_check_view(struct drm_encoder *encoder,
+                           struct drm_crtc_state *crtc_state,
+                           struct drm_connector_state *conn_state,
+                           struct drm_display_mode *native_mode)
 {
-       struct nouveau_drm *drm = nouveau_drm(crtc->dev);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       int ret;
+       struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
+       struct drm_display_mode *mode = &crtc_state->mode;
+       struct drm_connector *connector = conn_state->connector;
+       struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state);
+       struct nouveau_drm *drm = nouveau_drm(encoder->dev);
 
-       if (!crtc->primary->fb) {
-               NV_DEBUG(drm, "No FB bound\n");
+       NV_ATOMIC(drm, "%s atomic_check\n", encoder->name);
+       asyc->scaler.full = false;
+       if (!native_mode)
                return 0;
+
+       if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) {
+               switch (connector->connector_type) {
+               case DRM_MODE_CONNECTOR_LVDS:
+               case DRM_MODE_CONNECTOR_eDP:
+                       /* Force use of scaler for non-EDID modes. */
+                       if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
+                               break;
+                       mode = native_mode;
+                       asyc->scaler.full = true;
+                       break;
+               default:
+                       break;
+               }
+       } else {
+               mode = native_mode;
        }
 
-       ret = nv50_crtc_swap_fbs(crtc, old_fb);
-       if (ret)
-               return ret;
+       if (!drm_mode_equal(adjusted_mode, mode)) {
+               drm_mode_copy(adjusted_mode, mode);
+               crtc_state->mode_changed = true;
+       }
 
-       nv50_display_flip_stop(crtc);
-       nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
-       nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
        return 0;
 }
 
 static int
-nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
-                              struct drm_framebuffer *fb, int x, int y,
-                              enum mode_set_atomic state)
+nv50_outp_atomic_check(struct drm_encoder *encoder,
+                      struct drm_crtc_state *crtc_state,
+                      struct drm_connector_state *conn_state)
 {
-       WARN_ON(1);
-       return 0;
+       struct nouveau_connector *nv_connector =
+               nouveau_connector(conn_state->connector);
+       return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state,
+                                          nv_connector->native_mode);
 }
 
+/******************************************************************************
+ * DAC
+ *****************************************************************************/
 static void
-nv50_crtc_lut_load(struct drm_crtc *crtc)
+nv50_dac_dpms(struct drm_encoder *encoder, int mode)
 {
-       struct nv50_disp *disp = nv50_disp(crtc->dev);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
-       int i;
-
-       for (i = 0; i < 256; i++) {
-               u16 r = nv_crtc->lut.r[i] >> 2;
-               u16 g = nv_crtc->lut.g[i] >> 2;
-               u16 b = nv_crtc->lut.b[i] >> 2;
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct {
+               struct nv50_disp_mthd_v1 base;
+               struct nv50_disp_dac_pwr_v0 pwr;
+       } args = {
+               .base.version = 1,
+               .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
+               .base.hasht  = nv_encoder->dcb->hasht,
+               .base.hashm  = nv_encoder->dcb->hashm,
+               .pwr.state = 1,
+               .pwr.data  = 1,
+               .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
+                             mode != DRM_MODE_DPMS_OFF),
+               .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
+                             mode != DRM_MODE_DPMS_OFF),
+       };
 
-               if (disp->disp->oclass < GF110_DISP) {
-                       writew(r + 0x0000, lut + (i * 0x08) + 0);
-                       writew(g + 0x0000, lut + (i * 0x08) + 2);
-                       writew(b + 0x0000, lut + (i * 0x08) + 4);
-               } else {
-                       writew(r + 0x6000, lut + (i * 0x20) + 0);
-                       writew(g + 0x6000, lut + (i * 0x20) + 2);
-                       writew(b + 0x6000, lut + (i * 0x20) + 4);
-               }
-       }
+       nvif_mthd(disp->disp, 0, &args, sizeof(args));
 }
 
 static void
-nv50_crtc_disable(struct drm_crtc *crtc)
-{
-       struct nv50_head *head = nv50_head(crtc);
-       evo_sync(crtc->dev);
-       if (head->image)
-               nouveau_bo_unpin(head->image);
-       nouveau_bo_ref(NULL, &head->image);
-}
-
-static int
-nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
-                    uint32_t handle, uint32_t width, uint32_t height)
+nv50_dac_disable(struct drm_encoder *encoder)
 {
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       struct drm_gem_object *gem = NULL;
-       struct nouveau_bo *nvbo = NULL;
-       int ret = 0;
-
-       if (handle) {
-               if (width != 64 || height != 64)
-                       return -EINVAL;
-
-               gem = drm_gem_object_lookup(file_priv, handle);
-               if (unlikely(!gem))
-                       return -ENOENT;
-               nvbo = nouveau_gem_object(gem);
-
-               ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
-       }
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nv50_mast *mast = nv50_mast(encoder->dev);
+       const int or = nv_encoder->or;
+       u32 *push;
 
-       if (ret == 0) {
-               if (nv_crtc->cursor.nvbo)
-                       nouveau_bo_unpin(nv_crtc->cursor.nvbo);
-               nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
+       if (nv_encoder->crtc) {
+               push = evo_wait(mast, 4);
+               if (push) {
+                       if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
+                               evo_mthd(push, 0x0400 + (or * 0x080), 1);
+                               evo_data(push, 0x00000000);
+                       } else {
+                               evo_mthd(push, 0x0180 + (or * 0x020), 1);
+                               evo_data(push, 0x00000000);
+                       }
+                       evo_kick(push, mast);
+               }
        }
-       drm_gem_object_unreference_unlocked(gem);
 
-       nv50_crtc_cursor_show_hide(nv_crtc, true, true);
-       return ret;
+       nv_encoder->crtc = NULL;
 }
 
-static int
-nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
+static void
+nv50_dac_enable(struct drm_encoder *encoder)
 {
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       struct nv50_wndw *wndw = &nv50_head(crtc)->_curs->wndw;
-       struct nv50_wndw_atom *asyw = &wndw->asy;
+       struct nv50_mast *mast = nv50_mast(encoder->dev);
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
+       struct drm_display_mode *mode = &nv_crtc->base.state->adjusted_mode;
+       u32 *push;
 
-       asyw->point.x = x;
-       asyw->point.y = y;
-       asyw->set.point = true;
-       nv50_wndw_flush_set(wndw, 0, asyw);
+       push = evo_wait(mast, 8);
+       if (push) {
+               if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
+                       u32 syncs = 0x00000000;
 
-       nv_crtc->cursor_saved_x = x;
-       nv_crtc->cursor_saved_y = y;
-       return 0;
-}
+                       if (mode->flags & DRM_MODE_FLAG_NHSYNC)
+                               syncs |= 0x00000001;
+                       if (mode->flags & DRM_MODE_FLAG_NVSYNC)
+                               syncs |= 0x00000002;
 
-static int
-nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
-                   uint32_t size)
-{
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       u32 i;
+                       evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
+                       evo_data(push, 1 << nv_crtc->index);
+                       evo_data(push, syncs);
+               } else {
+                       u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
+                       u32 syncs = 0x00000001;
 
-       for (i = 0; i < size; i++) {
-               nv_crtc->lut.r[i] = r[i];
-               nv_crtc->lut.g[i] = g[i];
-               nv_crtc->lut.b[i] = b[i];
-       }
+                       if (mode->flags & DRM_MODE_FLAG_NHSYNC)
+                               syncs |= 0x00000008;
+                       if (mode->flags & DRM_MODE_FLAG_NVSYNC)
+                               syncs |= 0x00000010;
 
-       nv50_crtc_lut_load(crtc);
+                       if (mode->flags & DRM_MODE_FLAG_INTERLACE)
+                               magic |= 0x00000001;
 
-       return 0;
-}
+                       evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
+                       evo_data(push, syncs);
+                       evo_data(push, magic);
+                       evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
+                       evo_data(push, 1 << nv_crtc->index);
+               }
 
-static void
-nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
-{
-       nv50_crtc_cursor_move(&nv_crtc->base, x, y);
+               evo_kick(push, mast);
+       }
 
-       nv50_crtc_cursor_show_hide(nv_crtc, true, true);
+       nv_encoder->crtc = encoder->crtc;
 }
 
-static void
-nv50_crtc_destroy(struct drm_crtc *crtc)
+static enum drm_connector_status
+nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
 {
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
-       struct nv50_disp *disp = nv50_disp(crtc->dev);
-       struct nv50_head *head = nv50_head(crtc);
-
-       nv50_dmac_destroy(&head->ovly.base, disp->disp);
-       nv50_pioc_destroy(&head->oimm.base);
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct {
+               struct nv50_disp_mthd_v1 base;
+               struct nv50_disp_dac_load_v0 load;
+       } args = {
+               .base.version = 1,
+               .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
+               .base.hasht  = nv_encoder->dcb->hasht,
+               .base.hashm  = nv_encoder->dcb->hashm,
+       };
+       int ret;
 
-       /*XXX: this shouldn't be necessary, but the core doesn't call
-        *     disconnect() during the cleanup paths
-        */
-       if (head->image)
-               nouveau_bo_unpin(head->image);
-       nouveau_bo_ref(NULL, &head->image);
+       args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
+       if (args.load.data == 0)
+               args.load.data = 340;
+
+       ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
+       if (ret || !args.load.load)
+               return connector_status_disconnected;
 
-       /*XXX: ditto */
-       if (nv_crtc->cursor.nvbo)
-               nouveau_bo_unpin(nv_crtc->cursor.nvbo);
-       nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
+       return connector_status_connected;
+}
 
-       nouveau_bo_unmap(nv_crtc->lut.nvbo);
-       if (nv_crtc->lut.nvbo)
-               nouveau_bo_unpin(nv_crtc->lut.nvbo);
-       nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
+static const struct drm_encoder_helper_funcs
+nv50_dac_help = {
+       .dpms = nv50_dac_dpms,
+       .atomic_check = nv50_outp_atomic_check,
+       .enable = nv50_dac_enable,
+       .disable = nv50_dac_disable,
+       .detect = nv50_dac_detect
+};
 
-       drm_crtc_cleanup(crtc);
-       kfree(crtc);
+static void
+nv50_dac_destroy(struct drm_encoder *encoder)
+{
+       drm_encoder_cleanup(encoder);
+       kfree(encoder);
 }
 
-static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
-       .dpms = nv50_crtc_dpms,
-       .prepare = nv50_crtc_prepare,
-       .commit = nv50_crtc_commit,
-       .mode_fixup = nv50_crtc_mode_fixup,
-       .mode_set = nv50_crtc_mode_set,
-       .mode_set_base = nv50_crtc_mode_set_base,
-       .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
-       .load_lut = nv50_crtc_lut_load,
-       .disable = nv50_crtc_disable,
-       .atomic_check = nv50_head_atomic_check,
+static const struct drm_encoder_funcs
+nv50_dac_func = {
+       .destroy = nv50_dac_destroy,
 };
 
-/* This is identical to the version in the atomic helpers, except that
- * it supports non-vblanked ("async") page flips.
- */
 static int
-nv50_head_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
-                   struct drm_pending_vblank_event *event, u32 flags)
+nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
 {
-       struct drm_plane *plane = crtc->primary;
-       struct drm_atomic_state *state;
-       struct drm_plane_state *plane_state;
-       struct drm_crtc_state *crtc_state;
-       int ret = 0;
+       struct nouveau_drm *drm = nouveau_drm(connector->dev);
+       struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
+       struct nvkm_i2c_bus *bus;
+       struct nouveau_encoder *nv_encoder;
+       struct drm_encoder *encoder;
+       int type = DRM_MODE_ENCODER_DAC;
 
-       state = drm_atomic_state_alloc(plane->dev);
-       if (!state)
+       nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
+       if (!nv_encoder)
                return -ENOMEM;
+       nv_encoder->dcb = dcbe;
+       nv_encoder->or = ffs(dcbe->or) - 1;
 
-       state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
-retry:
-       crtc_state = drm_atomic_get_crtc_state(state, crtc);
-       if (IS_ERR(crtc_state)) {
-               ret = PTR_ERR(crtc_state);
-               goto fail;
-       }
-       crtc_state->event = event;
-
-       plane_state = drm_atomic_get_plane_state(state, plane);
-       if (IS_ERR(plane_state)) {
-               ret = PTR_ERR(plane_state);
-               goto fail;
-       }
-
-       ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
-       if (ret != 0)
-               goto fail;
-       drm_atomic_set_fb_for_plane(plane_state, fb);
-
-       /* Make sure we don't accidentally do a full modeset. */
-       state->allow_modeset = false;
-       if (!crtc_state->active) {
-               DRM_DEBUG_ATOMIC("[CRTC:%d] disabled, rejecting legacy flip\n",
-                                crtc->base.id);
-               ret = -EINVAL;
-               goto fail;
-       }
-
-       if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
-               nv50_wndw_atom(plane_state)->interval = 0;
-
-       ret = drm_atomic_nonblocking_commit(state);
-fail:
-       if (ret == -EDEADLK)
-               goto backoff;
-
-       drm_atomic_state_put(state);
-       return ret;
-
-backoff:
-       drm_atomic_state_clear(state);
-       drm_atomic_legacy_backoff(state);
+       bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
+       if (bus)
+               nv_encoder->i2c = &bus->i2c;
 
-       /*
-        * Someone might have exchanged the framebuffer while we dropped locks
-        * in the backoff code. We need to fix up the fb refcount tracking the
-        * core does for us.
-        */
-       plane->old_fb = plane->fb;
+       encoder = to_drm_encoder(nv_encoder);
+       encoder->possible_crtcs = dcbe->heads;
+       encoder->possible_clones = 0;
+       drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type,
+                        "dac-%04x-%04x", dcbe->hasht, dcbe->hashm);
+       drm_encoder_helper_add(encoder, &nv50_dac_help);
 
-       goto retry;
+       drm_mode_connector_attach_encoder(connector, encoder);
+       return 0;
 }
 
+/******************************************************************************
+ * Audio
+ *****************************************************************************/
 static void
-nv50_head_atomic_destroy_state(struct drm_crtc *crtc,
-                              struct drm_crtc_state *state)
+nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
 {
-       struct nv50_head_atom *asyh = nv50_head_atom(state);
-       __drm_atomic_helper_crtc_destroy_state(&asyh->state);
-       kfree(asyh);
-}
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct {
+               struct nv50_disp_mthd_v1 base;
+               struct nv50_disp_sor_hda_eld_v0 eld;
+       } args = {
+               .base.version = 1,
+               .base.method  = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
+               .base.hasht   = nv_encoder->dcb->hasht,
+               .base.hashm   = (0xf0ff & nv_encoder->dcb->hashm) |
+                               (0x0100 << nv_crtc->index),
+       };
 
-static struct drm_crtc_state *
-nv50_head_atomic_duplicate_state(struct drm_crtc *crtc)
-{
-       struct nv50_head_atom *armh = nv50_head_atom(crtc->state);
-       struct nv50_head_atom *asyh;
-       if (!(asyh = kmalloc(sizeof(*asyh), GFP_KERNEL)))
-               return NULL;
-       __drm_atomic_helper_crtc_duplicate_state(crtc, &asyh->state);
-       asyh->view = armh->view;
-       asyh->mode = armh->mode;
-       asyh->lut  = armh->lut;
-       asyh->core = armh->core;
-       asyh->curs = armh->curs;
-       asyh->base = armh->base;
-       asyh->ovly = armh->ovly;
-       asyh->dither = armh->dither;
-       asyh->procamp = armh->procamp;
-       asyh->clr.mask = 0;
-       asyh->set.mask = 0;
-       return &asyh->state;
+       nvif_mthd(disp->disp, 0, &args, sizeof(args));
 }
 
 static void
-__drm_atomic_helper_crtc_reset(struct drm_crtc *crtc,
-                              struct drm_crtc_state *state)
+nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
 {
-       if (crtc->state)
-               crtc->funcs->atomic_destroy_state(crtc, crtc->state);
-       crtc->state = state;
-       crtc->state->crtc = crtc;
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
+       struct nouveau_connector *nv_connector;
+       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct __packed {
+               struct {
+                       struct nv50_disp_mthd_v1 mthd;
+                       struct nv50_disp_sor_hda_eld_v0 eld;
+               } base;
+               u8 data[sizeof(nv_connector->base.eld)];
+       } args = {
+               .base.mthd.version = 1,
+               .base.mthd.method  = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
+               .base.mthd.hasht   = nv_encoder->dcb->hasht,
+               .base.mthd.hashm   = (0xf0ff & nv_encoder->dcb->hashm) |
+                                    (0x0100 << nv_crtc->index),
+       };
+
+       nv_connector = nouveau_encoder_connector_get(nv_encoder);
+       if (!drm_detect_monitor_audio(nv_connector->edid))
+               return;
+
+       drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
+       memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
+
+       nvif_mthd(disp->disp, 0, &args,
+                 sizeof(args.base) + drm_eld_size(args.data));
 }
 
+/******************************************************************************
+ * HDMI
+ *****************************************************************************/
 static void
-nv50_head_reset(struct drm_crtc *crtc)
+nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
 {
-       struct nv50_head_atom *asyh;
-
-       if (WARN_ON(!(asyh = kzalloc(sizeof(*asyh), GFP_KERNEL))))
-               return;
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct {
+               struct nv50_disp_mthd_v1 base;
+               struct nv50_disp_sor_hdmi_pwr_v0 pwr;
+       } args = {
+               .base.version = 1,
+               .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
+               .base.hasht  = nv_encoder->dcb->hasht,
+               .base.hashm  = (0xf0ff & nv_encoder->dcb->hashm) |
+                              (0x0100 << nv_crtc->index),
+       };
 
-       __drm_atomic_helper_crtc_reset(crtc, &asyh->state);
+       nvif_mthd(disp->disp, 0, &args, sizeof(args));
 }
 
-static const struct drm_crtc_funcs nv50_crtc_func = {
-       .reset = nv50_head_reset,
-       .cursor_set = nv50_crtc_cursor_set,
-       .cursor_move = nv50_crtc_cursor_move,
-       .gamma_set = nv50_crtc_gamma_set,
-       .destroy = nv50_crtc_destroy,
-       .set_config = drm_atomic_helper_set_config,
-       .page_flip = nv50_head_page_flip,
-       .set_property = drm_atomic_helper_crtc_set_property,
-       .atomic_duplicate_state = nv50_head_atomic_duplicate_state,
-       .atomic_destroy_state = nv50_head_atomic_destroy_state,
-};
-
-static int
-nv50_crtc_create(struct drm_device *dev, int index)
+static void
+nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
 {
-       struct nouveau_drm *drm = nouveau_drm(dev);
-       struct nvif_device *device = &drm->device;
-       struct nv50_disp *disp = nv50_disp(dev);
-       struct nv50_head *head;
-       struct nv50_base *base;
-       struct nv50_curs *curs;
-       struct drm_crtc *crtc;
-       int ret, i;
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+       struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
+       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct {
+               struct nv50_disp_mthd_v1 base;
+               struct nv50_disp_sor_hdmi_pwr_v0 pwr;
+       } args = {
+               .base.version = 1,
+               .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
+               .base.hasht  = nv_encoder->dcb->hasht,
+               .base.hashm  = (0xf0ff & nv_encoder->dcb->hashm) |
+                              (0x0100 << nv_crtc->index),
+               .pwr.state = 1,
+               .pwr.rekey = 56, /* binary driver, and tegra, constant */
+       };
+       struct nouveau_connector *nv_connector;
+       u32 max_ac_packet;
 
-       head = kzalloc(sizeof(*head), GFP_KERNEL);
-       if (!head)
-               return -ENOMEM;
+       nv_connector = nouveau_encoder_connector_get(nv_encoder);
+       if (!drm_detect_hdmi_monitor(nv_connector->edid))
+               return;
 
-       head->base.index = index;
-       head->base.color_vibrance = 50;
-       head->base.vibrant_hue = 0;
-       head->base.cursor.set_pos = nv50_crtc_cursor_restore;
-       for (i = 0; i < 256; i++) {
-               head->base.lut.r[i] = i << 8;
-               head->base.lut.g[i] = i << 8;
-               head->base.lut.b[i] = i << 8;
-       }
+       max_ac_packet  = mode->htotal - mode->hdisplay;
+       max_ac_packet -= args.pwr.rekey;
+       max_ac_packet -= 18; /* constant from tegra */
+       args.pwr.max_ac_packet = max_ac_packet / 32;
 
-       ret = nv50_base_new(drm, head, &base);
-       if (ret == 0)
-               ret = nv50_curs_new(drm, head, &curs);
-       if (ret) {
-               kfree(head);
-               return ret;
-       }
+       nvif_mthd(disp->disp, 0, &args, sizeof(args));
+       nv50_audio_enable(encoder, mode);
+}
 
-       crtc = &head->base.base;
-       head->_base = base;
-       head->_curs = curs;
+/******************************************************************************
+ * MST
+ *****************************************************************************/
+#define nv50_mstm(p) container_of((p), struct nv50_mstm, mgr)
+#define nv50_mstc(p) container_of((p), struct nv50_mstc, connector)
+#define nv50_msto(p) container_of((p), struct nv50_msto, encoder)
 
-       drm_crtc_init_with_planes(dev, crtc, &base->wndw.plane,
-                                 &curs->wndw.plane, &nv50_crtc_func,
-                                 "head-%d", head->base.index);
-       drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
-       drm_mode_crtc_set_gamma_size(crtc, 256);
+struct nv50_mstm {
+       struct nouveau_encoder *outp;
 
-       ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
-                            0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
-       if (!ret) {
-               ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
-               if (!ret) {
-                       ret = nouveau_bo_map(head->base.lut.nvbo);
-                       if (ret)
-                               nouveau_bo_unpin(head->base.lut.nvbo);
-               }
-               if (ret)
-                       nouveau_bo_ref(NULL, &head->base.lut.nvbo);
-       }
+       struct drm_dp_mst_topology_mgr mgr;
+       struct nv50_msto *msto[4];
+
+       bool modified;
+};
 
-       if (ret)
-               goto out;
+struct nv50_mstc {
+       struct nv50_mstm *mstm;
+       struct drm_dp_mst_port *port;
+       struct drm_connector connector;
 
-       /* allocate overlay resources */
-       ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
-       if (ret)
-               goto out;
+       struct drm_display_mode *native;
+       struct edid *edid;
 
-       ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
-                              &head->ovly);
-       if (ret)
-               goto out;
+       int pbn;
+};
 
-out:
-       if (ret)
-               nv50_crtc_destroy(crtc);
-       return ret;
-}
+struct nv50_msto {
+       struct drm_encoder encoder;
 
-/******************************************************************************
- * Output path helpers
- *****************************************************************************/
-static int
-nv50_outp_atomic_check_view(struct drm_encoder *encoder,
-                           struct drm_crtc_state *crtc_state,
-                           struct drm_connector_state *conn_state,
-                           struct drm_display_mode *native_mode)
-{
-       struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode;
-       struct drm_display_mode *mode = &crtc_state->mode;
-       struct drm_connector *connector = conn_state->connector;
-       struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state);
-       struct nouveau_drm *drm = nouveau_drm(encoder->dev);
+       struct nv50_head *head;
+       struct nv50_mstc *mstc;
+       bool disabled;
+};
 
-       NV_ATOMIC(drm, "%s atomic_check\n", encoder->name);
-       asyc->scaler.full = false;
-       if (!native_mode)
-               return 0;
+static struct drm_dp_payload *
+nv50_msto_payload(struct nv50_msto *msto)
+{
+       struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev);
+       struct nv50_mstc *mstc = msto->mstc;
+       struct nv50_mstm *mstm = mstc->mstm;
+       int vcpi = mstc->port->vcpi.vcpi, i;
 
-       if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) {
-               switch (connector->connector_type) {
-               case DRM_MODE_CONNECTOR_LVDS:
-               case DRM_MODE_CONNECTOR_eDP:
-                       /* Force use of scaler for non-EDID modes. */
-                       if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
-                               break;
-                       mode = native_mode;
-                       asyc->scaler.full = true;
-                       break;
-               default:
-                       break;
-               }
-       } else {
-               mode = native_mode;
+       NV_ATOMIC(drm, "%s: vcpi %d\n", msto->encoder.name, vcpi);
+       for (i = 0; i < mstm->mgr.max_payloads; i++) {
+               struct drm_dp_payload *payload = &mstm->mgr.payloads[i];
+               NV_ATOMIC(drm, "%s: %d: vcpi %d start 0x%02x slots 0x%02x\n",
+                         mstm->outp->base.base.name, i, payload->vcpi,
+                         payload->start_slot, payload->num_slots);
        }
 
-       if (!drm_mode_equal(adjusted_mode, mode)) {
-               drm_mode_copy(adjusted_mode, mode);
-               crtc_state->mode_changed = true;
+       for (i = 0; i < mstm->mgr.max_payloads; i++) {
+               struct drm_dp_payload *payload = &mstm->mgr.payloads[i];
+               if (payload->vcpi == vcpi)
+                       return payload;
        }
 
-       return 0;
+       return NULL;
 }
 
-static int
-nv50_outp_atomic_check(struct drm_encoder *encoder,
-                      struct drm_crtc_state *crtc_state,
-                      struct drm_connector_state *conn_state)
-{
-       struct nouveau_connector *nv_connector =
-               nouveau_connector(conn_state->connector);
-       return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state,
-                                          nv_connector->native_mode);
+static void
+nv50_msto_cleanup(struct nv50_msto *msto)
+{
+       struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev);
+       struct nv50_mstc *mstc = msto->mstc;
+       struct nv50_mstm *mstm = mstc->mstm;
+
+       NV_ATOMIC(drm, "%s: msto cleanup\n", msto->encoder.name);
+       if (mstc->port && mstc->port->vcpi.vcpi > 0 && !nv50_msto_payload(msto))
+               drm_dp_mst_deallocate_vcpi(&mstm->mgr, mstc->port);
+       if (msto->disabled) {
+               msto->mstc = NULL;
+               msto->head = NULL;
+               msto->disabled = false;
+       }
 }
 
-/******************************************************************************
- * DAC
- *****************************************************************************/
 static void
-nv50_dac_dpms(struct drm_encoder *encoder, int mode)
+nv50_msto_prepare(struct nv50_msto *msto)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev);
+       struct nv50_mstc *mstc = msto->mstc;
+       struct nv50_mstm *mstm = mstc->mstm;
        struct {
                struct nv50_disp_mthd_v1 base;
-               struct nv50_disp_dac_pwr_v0 pwr;
+               struct nv50_disp_sor_dp_mst_vcpi_v0 vcpi;
        } args = {
                .base.version = 1,
-               .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
-               .base.hasht  = nv_encoder->dcb->hasht,
-               .base.hashm  = nv_encoder->dcb->hashm,
-               .pwr.state = 1,
-               .pwr.data  = 1,
-               .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
-                             mode != DRM_MODE_DPMS_OFF),
-               .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
-                             mode != DRM_MODE_DPMS_OFF),
+               .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI,
+               .base.hasht  = mstm->outp->dcb->hasht,
+               .base.hashm  = (0xf0ff & mstm->outp->dcb->hashm) |
+                              (0x0100 << msto->head->base.index),
        };
 
-       nvif_mthd(disp->disp, 0, &args, sizeof(args));
+       NV_ATOMIC(drm, "%s: msto prepare\n", msto->encoder.name);
+       if (mstc->port && mstc->port->vcpi.vcpi > 0) {
+               struct drm_dp_payload *payload = nv50_msto_payload(msto);
+               if (payload) {
+                       args.vcpi.start_slot = payload->start_slot;
+                       args.vcpi.num_slots = payload->num_slots;
+                       args.vcpi.pbn = mstc->port->vcpi.pbn;
+                       args.vcpi.aligned_pbn = mstc->port->vcpi.aligned_pbn;
+               }
+       }
+
+       NV_ATOMIC(drm, "%s: %s: %02x %02x %04x %04x\n",
+                 msto->encoder.name, msto->head->base.base.name,
+                 args.vcpi.start_slot, args.vcpi.num_slots,
+                 args.vcpi.pbn, args.vcpi.aligned_pbn);
+       nvif_mthd(&drm->display->disp, 0, &args, sizeof(args));
+}
+
+static int
+nv50_msto_atomic_check(struct drm_encoder *encoder,
+                      struct drm_crtc_state *crtc_state,
+                      struct drm_connector_state *conn_state)
+{
+       struct nv50_mstc *mstc = nv50_mstc(conn_state->connector);
+       struct nv50_mstm *mstm = mstc->mstm;
+       int bpp = conn_state->connector->display_info.bpc * 3;
+       int slots;
+
+       mstc->pbn = drm_dp_calc_pbn_mode(crtc_state->adjusted_mode.clock, bpp);
+
+       slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn);
+       if (slots < 0)
+               return slots;
+
+       return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state,
+                                          mstc->native);
 }
 
 static void
-nv50_dac_disable(struct drm_encoder *encoder)
+nv50_msto_enable(struct drm_encoder *encoder)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nv50_mast *mast = nv50_mast(encoder->dev);
-       const int or = nv_encoder->or;
-       u32 *push;
+       struct nv50_head *head = nv50_head(encoder->crtc);
+       struct nv50_msto *msto = nv50_msto(encoder);
+       struct nv50_mstc *mstc = NULL;
+       struct nv50_mstm *mstm = NULL;
+       struct drm_connector *connector;
+       u8 proto, depth;
+       int slots;
+       bool r;
 
-       if (nv_encoder->crtc) {
-               push = evo_wait(mast, 4);
-               if (push) {
-                       if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
-                               evo_mthd(push, 0x0400 + (or * 0x080), 1);
-                               evo_data(push, 0x00000000);
-                       } else {
-                               evo_mthd(push, 0x0180 + (or * 0x020), 1);
-                               evo_data(push, 0x00000000);
-                       }
-                       evo_kick(push, mast);
+       drm_for_each_connector(connector, encoder->dev) {
+               if (connector->state->best_encoder == &msto->encoder) {
+                       mstc = nv50_mstc(connector);
+                       mstm = mstc->mstm;
+                       break;
                }
        }
 
-       nv_encoder->crtc = NULL;
+       if (WARN_ON(!mstc))
+               return;
+
+       r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, &slots);
+       WARN_ON(!r);
+
+       if (mstm->outp->dcb->sorconf.link & 1)
+               proto = 0x8;
+       else
+               proto = 0x9;
+
+       switch (mstc->connector.display_info.bpc) {
+       case  6: depth = 0x2; break;
+       case  8: depth = 0x5; break;
+       case 10:
+       default: depth = 0x6; break;
+       }
+
+       mstm->outp->update(mstm->outp, head->base.index,
+                          &head->base.base.state->adjusted_mode, proto, depth);
+
+       msto->head = head;
+       msto->mstc = mstc;
+       mstm->modified = true;
 }
 
 static void
-nv50_dac_enable(struct drm_encoder *encoder)
+nv50_msto_disable(struct drm_encoder *encoder)
 {
-       struct nv50_mast *mast = nv50_mast(encoder->dev);
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
-       struct drm_display_mode *mode = &nv_crtc->base.state->adjusted_mode;
-       u32 *push;
+       struct nv50_msto *msto = nv50_msto(encoder);
+       struct nv50_mstc *mstc = msto->mstc;
+       struct nv50_mstm *mstm = mstc->mstm;
 
-       push = evo_wait(mast, 8);
-       if (push) {
-               if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
-                       u32 syncs = 0x00000000;
+       if (mstc->port)
+               drm_dp_mst_reset_vcpi_slots(&mstm->mgr, mstc->port);
 
-                       if (mode->flags & DRM_MODE_FLAG_NHSYNC)
-                               syncs |= 0x00000001;
-                       if (mode->flags & DRM_MODE_FLAG_NVSYNC)
-                               syncs |= 0x00000002;
+       mstm->outp->update(mstm->outp, msto->head->base.index, NULL, 0, 0);
+       mstm->modified = true;
+       msto->disabled = true;
+}
 
-                       evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
-                       evo_data(push, 1 << nv_crtc->index);
-                       evo_data(push, syncs);
-               } else {
-                       u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
-                       u32 syncs = 0x00000001;
+static const struct drm_encoder_helper_funcs
+nv50_msto_help = {
+       .disable = nv50_msto_disable,
+       .enable = nv50_msto_enable,
+       .atomic_check = nv50_msto_atomic_check,
+};
 
-                       if (mode->flags & DRM_MODE_FLAG_NHSYNC)
-                               syncs |= 0x00000008;
-                       if (mode->flags & DRM_MODE_FLAG_NVSYNC)
-                               syncs |= 0x00000010;
+static void
+nv50_msto_destroy(struct drm_encoder *encoder)
+{
+       struct nv50_msto *msto = nv50_msto(encoder);
+       drm_encoder_cleanup(&msto->encoder);
+       kfree(msto);
+}
 
-                       if (mode->flags & DRM_MODE_FLAG_INTERLACE)
-                               magic |= 0x00000001;
+static const struct drm_encoder_funcs
+nv50_msto = {
+       .destroy = nv50_msto_destroy,
+};
 
-                       evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
-                       evo_data(push, syncs);
-                       evo_data(push, magic);
-                       evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
-                       evo_data(push, 1 << nv_crtc->index);
-               }
+static int
+nv50_msto_new(struct drm_device *dev, u32 heads, const char *name, int id,
+             struct nv50_msto **pmsto)
+{
+       struct nv50_msto *msto;
+       int ret;
 
-               evo_kick(push, mast);
+       if (!(msto = *pmsto = kzalloc(sizeof(*msto), GFP_KERNEL)))
+               return -ENOMEM;
+
+       ret = drm_encoder_init(dev, &msto->encoder, &nv50_msto,
+                              DRM_MODE_ENCODER_DPMST, "%s-mst-%d", name, id);
+       if (ret) {
+               kfree(*pmsto);
+               *pmsto = NULL;
+               return ret;
        }
 
-       nv_encoder->crtc = encoder->crtc;
+       drm_encoder_helper_add(&msto->encoder, &nv50_msto_help);
+       msto->encoder.possible_crtcs = heads;
+       return 0;
 }
 
-static enum drm_connector_status
-nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
+static struct drm_encoder *
+nv50_mstc_atomic_best_encoder(struct drm_connector *connector,
+                             struct drm_connector_state *connector_state)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nv50_disp *disp = nv50_disp(encoder->dev);
-       struct {
-               struct nv50_disp_mthd_v1 base;
-               struct nv50_disp_dac_load_v0 load;
-       } args = {
-               .base.version = 1,
-               .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
-               .base.hasht  = nv_encoder->dcb->hasht,
-               .base.hashm  = nv_encoder->dcb->hashm,
-       };
-       int ret;
+       struct nv50_head *head = nv50_head(connector_state->crtc);
+       struct nv50_mstc *mstc = nv50_mstc(connector);
+       if (mstc->port) {
+               struct nv50_mstm *mstm = mstc->mstm;
+               return &mstm->msto[head->base.index]->encoder;
+       }
+       return NULL;
+}
 
-       args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
-       if (args.load.data == 0)
-               args.load.data = 340;
+static struct drm_encoder *
+nv50_mstc_best_encoder(struct drm_connector *connector)
+{
+       struct nv50_mstc *mstc = nv50_mstc(connector);
+       if (mstc->port) {
+               struct nv50_mstm *mstm = mstc->mstm;
+               return &mstm->msto[0]->encoder;
+       }
+       return NULL;
+}
 
-       ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
-       if (ret || !args.load.load)
-               return connector_status_disconnected;
+static enum drm_mode_status
+nv50_mstc_mode_valid(struct drm_connector *connector,
+                    struct drm_display_mode *mode)
+{
+       return MODE_OK;
+}
 
-       return connector_status_connected;
+static int
+nv50_mstc_get_modes(struct drm_connector *connector)
+{
+       struct nv50_mstc *mstc = nv50_mstc(connector);
+       int ret = 0;
+
+       mstc->edid = drm_dp_mst_get_edid(&mstc->connector, mstc->port->mgr, mstc->port);
+       drm_mode_connector_update_edid_property(&mstc->connector, mstc->edid);
+       if (mstc->edid) {
+               ret = drm_add_edid_modes(&mstc->connector, mstc->edid);
+               drm_edid_to_eld(&mstc->connector, mstc->edid);
+       }
+
+       if (!mstc->connector.display_info.bpc)
+               mstc->connector.display_info.bpc = 8;
+
+       if (mstc->native)
+               drm_mode_destroy(mstc->connector.dev, mstc->native);
+       mstc->native = nouveau_conn_native_mode(&mstc->connector);
+       return ret;
 }
 
-static const struct drm_encoder_helper_funcs
-nv50_dac_help = {
-       .dpms = nv50_dac_dpms,
-       .atomic_check = nv50_outp_atomic_check,
-       .enable = nv50_dac_enable,
-       .disable = nv50_dac_disable,
-       .get_crtc = nv50_display_crtc_get,
-       .detect = nv50_dac_detect
+static const struct drm_connector_helper_funcs
+nv50_mstc_help = {
+       .get_modes = nv50_mstc_get_modes,
+       .mode_valid = nv50_mstc_mode_valid,
+       .best_encoder = nv50_mstc_best_encoder,
+       .atomic_best_encoder = nv50_mstc_atomic_best_encoder,
 };
 
-static void
-nv50_dac_destroy(struct drm_encoder *encoder)
+static enum drm_connector_status
+nv50_mstc_detect(struct drm_connector *connector, bool force)
 {
-       drm_encoder_cleanup(encoder);
-       kfree(encoder);
+       struct nv50_mstc *mstc = nv50_mstc(connector);
+       if (!mstc->port)
+               return connector_status_disconnected;
+       return drm_dp_mst_detect_port(connector, mstc->port->mgr, mstc->port);
 }
 
-static const struct drm_encoder_funcs
-nv50_dac_func = {
-       .destroy = nv50_dac_destroy,
+static void
+nv50_mstc_destroy(struct drm_connector *connector)
+{
+       struct nv50_mstc *mstc = nv50_mstc(connector);
+       drm_connector_cleanup(&mstc->connector);
+       kfree(mstc);
+}
+
+static const struct drm_connector_funcs
+nv50_mstc = {
+       .dpms = drm_atomic_helper_connector_dpms,
+       .reset = nouveau_conn_reset,
+       .detect = nv50_mstc_detect,
+       .fill_modes = drm_helper_probe_single_connector_modes,
+       .set_property = drm_atomic_helper_connector_set_property,
+       .destroy = nv50_mstc_destroy,
+       .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state,
+       .atomic_destroy_state = nouveau_conn_atomic_destroy_state,
+       .atomic_set_property = nouveau_conn_atomic_set_property,
+       .atomic_get_property = nouveau_conn_atomic_get_property,
 };
 
 static int
-nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
+nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port,
+             const char *path, struct nv50_mstc **pmstc)
 {
-       struct nouveau_drm *drm = nouveau_drm(connector->dev);
-       struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
-       struct nvkm_i2c_bus *bus;
-       struct nouveau_encoder *nv_encoder;
-       struct drm_encoder *encoder;
-       int type = DRM_MODE_ENCODER_DAC;
+       struct drm_device *dev = mstm->outp->base.base.dev;
+       struct nv50_mstc *mstc;
+       int ret, i;
 
-       nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
-       if (!nv_encoder)
+       if (!(mstc = *pmstc = kzalloc(sizeof(*mstc), GFP_KERNEL)))
                return -ENOMEM;
-       nv_encoder->dcb = dcbe;
-       nv_encoder->or = ffs(dcbe->or) - 1;
-
-       bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
-       if (bus)
-               nv_encoder->i2c = &bus->i2c;
+       mstc->mstm = mstm;
+       mstc->port = port;
 
-       encoder = to_drm_encoder(nv_encoder);
-       encoder->possible_crtcs = dcbe->heads;
-       encoder->possible_clones = 0;
-       drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type,
-                        "dac-%04x-%04x", dcbe->hasht, dcbe->hashm);
-       drm_encoder_helper_add(encoder, &nv50_dac_help);
+       ret = drm_connector_init(dev, &mstc->connector, &nv50_mstc,
+                                DRM_MODE_CONNECTOR_DisplayPort);
+       if (ret) {
+               kfree(*pmstc);
+               *pmstc = NULL;
+               return ret;
+       }
 
-       drm_mode_connector_attach_encoder(connector, encoder);
+       drm_connector_helper_add(&mstc->connector, &nv50_mstc_help);
+
+       mstc->connector.funcs->reset(&mstc->connector);
+       nouveau_conn_attach_properties(&mstc->connector);
+
+       for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto; i++)
+               drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder);
+
+       drm_object_attach_property(&mstc->connector.base, dev->mode_config.path_property, 0);
+       drm_object_attach_property(&mstc->connector.base, dev->mode_config.tile_property, 0);
+       drm_mode_connector_set_path_property(&mstc->connector, path);
        return 0;
 }
 
-/******************************************************************************
- * Audio
- *****************************************************************************/
 static void
-nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
+nv50_mstm_cleanup(struct nv50_mstm *mstm)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nv50_disp *disp = nv50_disp(encoder->dev);
-       struct {
-               struct nv50_disp_mthd_v1 base;
-               struct nv50_disp_sor_hda_eld_v0 eld;
-       } args = {
-               .base.version = 1,
-               .base.method  = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
-               .base.hasht   = nv_encoder->dcb->hasht,
-               .base.hashm   = (0xf0ff & nv_encoder->dcb->hashm) |
-                               (0x0100 << nv_crtc->index),
-       };
+       struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev);
+       struct drm_encoder *encoder;
+       int ret;
 
-       nvif_mthd(disp->disp, 0, &args, sizeof(args));
+       NV_ATOMIC(drm, "%s: mstm cleanup\n", mstm->outp->base.base.name);
+       ret = drm_dp_check_act_status(&mstm->mgr);
+
+       ret = drm_dp_update_payload_part2(&mstm->mgr);
+
+       drm_for_each_encoder(encoder, mstm->outp->base.base.dev) {
+               if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
+                       struct nv50_msto *msto = nv50_msto(encoder);
+                       struct nv50_mstc *mstc = msto->mstc;
+                       if (mstc && mstc->mstm == mstm)
+                               nv50_msto_cleanup(msto);
+               }
+       }
+
+       mstm->modified = false;
 }
 
 static void
-nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
+nv50_mstm_prepare(struct nv50_mstm *mstm)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
-       struct nouveau_connector *nv_connector;
-       struct nv50_disp *disp = nv50_disp(encoder->dev);
-       struct __packed {
-               struct {
-                       struct nv50_disp_mthd_v1 mthd;
-                       struct nv50_disp_sor_hda_eld_v0 eld;
-               } base;
-               u8 data[sizeof(nv_connector->base.eld)];
-       } args = {
-               .base.mthd.version = 1,
-               .base.mthd.method  = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
-               .base.mthd.hasht   = nv_encoder->dcb->hasht,
-               .base.mthd.hashm   = (0xf0ff & nv_encoder->dcb->hashm) |
-                                    (0x0100 << nv_crtc->index),
-       };
+       struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev);
+       struct drm_encoder *encoder;
+       int ret;
 
-       nv_connector = nouveau_encoder_connector_get(nv_encoder);
-       if (!drm_detect_monitor_audio(nv_connector->edid))
-               return;
+       NV_ATOMIC(drm, "%s: mstm prepare\n", mstm->outp->base.base.name);
+       ret = drm_dp_update_payload_part1(&mstm->mgr);
 
-       drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
-       memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
+       drm_for_each_encoder(encoder, mstm->outp->base.base.dev) {
+               if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) {
+                       struct nv50_msto *msto = nv50_msto(encoder);
+                       struct nv50_mstc *mstc = msto->mstc;
+                       if (mstc && mstc->mstm == mstm)
+                               nv50_msto_prepare(msto);
+               }
+       }
+}
 
-       nvif_mthd(disp->disp, 0, &args,
-                 sizeof(args.base) + drm_eld_size(args.data));
+static void
+nv50_mstm_hotplug(struct drm_dp_mst_topology_mgr *mgr)
+{
+       struct nv50_mstm *mstm = nv50_mstm(mgr);
+       drm_kms_helper_hotplug_event(mstm->outp->base.base.dev);
 }
 
-/******************************************************************************
- * HDMI
- *****************************************************************************/
 static void
-nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
+nv50_mstm_destroy_connector(struct drm_dp_mst_topology_mgr *mgr,
+                           struct drm_connector *connector)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nv50_disp *disp = nv50_disp(encoder->dev);
-       struct {
-               struct nv50_disp_mthd_v1 base;
-               struct nv50_disp_sor_hdmi_pwr_v0 pwr;
-       } args = {
-               .base.version = 1,
-               .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
-               .base.hasht  = nv_encoder->dcb->hasht,
-               .base.hashm  = (0xf0ff & nv_encoder->dcb->hashm) |
-                              (0x0100 << nv_crtc->index),
-       };
+       struct nouveau_drm *drm = nouveau_drm(connector->dev);
+       struct nv50_mstc *mstc = nv50_mstc(connector);
 
-       nvif_mthd(disp->disp, 0, &args, sizeof(args));
+       drm_connector_unregister(&mstc->connector);
+
+       drm_modeset_lock_all(drm->dev);
+       drm_fb_helper_remove_one_connector(&drm->fbcon->helper, &mstc->connector);
+       mstc->port = NULL;
+       drm_modeset_unlock_all(drm->dev);
+
+       drm_connector_unreference(&mstc->connector);
 }
 
 static void
-nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode)
+nv50_mstm_register_connector(struct drm_connector *connector)
 {
-       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
-       struct nv50_disp *disp = nv50_disp(encoder->dev);
-       struct {
-               struct nv50_disp_mthd_v1 base;
-               struct nv50_disp_sor_hdmi_pwr_v0 pwr;
-       } args = {
-               .base.version = 1,
-               .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
-               .base.hasht  = nv_encoder->dcb->hasht,
-               .base.hashm  = (0xf0ff & nv_encoder->dcb->hashm) |
-                              (0x0100 << nv_crtc->index),
-               .pwr.state = 1,
-               .pwr.rekey = 56, /* binary driver, and tegra, constant */
-       };
-       struct nouveau_connector *nv_connector;
-       u32 max_ac_packet;
-
-       nv_connector = nouveau_encoder_connector_get(nv_encoder);
-       if (!drm_detect_hdmi_monitor(nv_connector->edid))
-               return;
+       struct nouveau_drm *drm = nouveau_drm(connector->dev);
 
-       max_ac_packet  = mode->htotal - mode->hdisplay;
-       max_ac_packet -= args.pwr.rekey;
-       max_ac_packet -= 18; /* constant from tegra */
-       args.pwr.max_ac_packet = max_ac_packet / 32;
+       drm_modeset_lock_all(drm->dev);
+       drm_fb_helper_add_one_connector(&drm->fbcon->helper, connector);
+       drm_modeset_unlock_all(drm->dev);
 
-       nvif_mthd(disp->disp, 0, &args, sizeof(args));
-       nv50_audio_enable(encoder, mode);
+       drm_connector_register(connector);
 }
 
-/******************************************************************************
- * MST
- *****************************************************************************/
-struct nv50_mstm {
-       struct nouveau_encoder *outp;
+static struct drm_connector *
+nv50_mstm_add_connector(struct drm_dp_mst_topology_mgr *mgr,
+                       struct drm_dp_mst_port *port, const char *path)
+{
+       struct nv50_mstm *mstm = nv50_mstm(mgr);
+       struct nv50_mstc *mstc;
+       int ret;
 
-       struct drm_dp_mst_topology_mgr mgr;
+       ret = nv50_mstc_new(mstm, port, path, &mstc);
+       if (ret) {
+               if (mstc)
+                       mstc->connector.funcs->destroy(&mstc->connector);
+               return NULL;
+       }
+
+       return &mstc->connector;
+}
+
+static const struct drm_dp_mst_topology_cbs
+nv50_mstm = {
+       .add_connector = nv50_mstm_add_connector,
+       .register_connector = nv50_mstm_register_connector,
+       .destroy_connector = nv50_mstm_destroy_connector,
+       .hotplug = nv50_mstm_hotplug,
 };
 
+void
+nv50_mstm_service(struct nv50_mstm *mstm)
+{
+       struct drm_dp_aux *aux = mstm->mgr.aux;
+       bool handled = true;
+       int ret;
+       u8 esi[8] = {};
+
+       while (handled) {
+               ret = drm_dp_dpcd_read(aux, DP_SINK_COUNT_ESI, esi, 8);
+               if (ret != 8) {
+                       drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false);
+                       return;
+               }
+
+               drm_dp_mst_hpd_irq(&mstm->mgr, esi, &handled);
+               if (!handled)
+                       break;
+
+               drm_dp_dpcd_write(aux, DP_SINK_COUNT_ESI + 1, &esi[1], 3);
+       }
+}
+
+void
+nv50_mstm_remove(struct nv50_mstm *mstm)
+{
+       if (mstm)
+               drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false);
+}
+
 static int
 nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state)
 {
@@ -3432,12 +3346,15 @@ nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow)
        if (!mstm)
                return 0;
 
-       if (dpcd[0] >= 0x12 && allow) {
+       if (dpcd[0] >= 0x12) {
                ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]);
                if (ret < 0)
                        return ret;
 
-               state = dpcd[1] & DP_MST_CAP;
+               if (!(dpcd[1] & DP_MST_CAP))
+                       dpcd[0] = 0x11;
+               else
+                       state = allow;
        }
 
        ret = nv50_mstm_enable(mstm, dpcd[0], state);
@@ -3451,6 +3368,20 @@ nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow)
        return mstm->mgr.mst_state;
 }
 
+static void
+nv50_mstm_fini(struct nv50_mstm *mstm)
+{
+       if (mstm && mstm->mgr.mst_state)
+               drm_dp_mst_topology_mgr_suspend(&mstm->mgr);
+}
+
+static void
+nv50_mstm_init(struct nv50_mstm *mstm)
+{
+       if (mstm && mstm->mgr.mst_state)
+               drm_dp_mst_topology_mgr_resume(&mstm->mgr);
+}
+
 static void
 nv50_mstm_del(struct nv50_mstm **pmstm)
 {
@@ -3468,17 +3399,36 @@ nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max,
        const int max_payloads = hweight8(outp->dcb->heads);
        struct drm_device *dev = outp->base.base.dev;
        struct nv50_mstm *mstm;
-       int ret;
+       int ret, i;
+       u8 dpcd;
+
+       /* This is a workaround for some monitors not functioning
+        * correctly in MST mode on initial module load.  I think
+        * some bad interaction with the VBIOS may be responsible.
+        *
+        * A good ol' off and on again seems to work here ;)
+        */
+       ret = drm_dp_dpcd_readb(aux, DP_DPCD_REV, &dpcd);
+       if (ret >= 0 && dpcd >= 0x12)
+               drm_dp_dpcd_writeb(aux, DP_MSTM_CTRL, 0);
 
        if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL)))
                return -ENOMEM;
        mstm->outp = outp;
+       mstm->mgr.cbs = &nv50_mstm;
 
        ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev->dev, aux, aux_max,
                                           max_payloads, conn_base_id);
        if (ret)
                return ret;
 
+       for (i = 0; i < max_payloads; i++) {
+               ret = nv50_msto_new(dev, outp->dcb->heads, outp->base.base.name,
+                                   i, &mstm->msto[i]);
+               if (ret)
+                       return ret;
+       }
+
        return 0;
 }
 
@@ -3500,58 +3450,55 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
                .base.hashm  = nv_encoder->dcb->hashm,
                .pwr.state = mode == DRM_MODE_DPMS_ON,
        };
-       struct {
-               struct nv50_disp_mthd_v1 base;
-               struct nv50_disp_sor_dp_pwr_v0 pwr;
-       } link = {
-               .base.version = 1,
-               .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
-               .base.hasht  = nv_encoder->dcb->hasht,
-               .base.hashm  = nv_encoder->dcb->hashm,
-               .pwr.state = mode == DRM_MODE_DPMS_ON,
-       };
-       struct drm_device *dev = encoder->dev;
-       struct drm_encoder *partner;
 
-       nv_encoder->last_dpms = mode;
-
-       list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
-               struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
-
-               if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
-                       continue;
+       nvif_mthd(disp->disp, 0, &args, sizeof(args));
+}
 
-               if (nv_partner != nv_encoder &&
-                   nv_partner->dcb->or == nv_encoder->dcb->or) {
-                       if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
-                               return;
-                       break;
-               }
-       }
+static void
+nv50_sor_update(struct nouveau_encoder *nv_encoder, u8 head,
+               struct drm_display_mode *mode, u8 proto, u8 depth)
+{
+       struct nv50_dmac *core = &nv50_mast(nv_encoder->base.base.dev)->base;
+       u32 *push;
 
-       if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
-               args.pwr.state = 1;
-               nvif_mthd(disp->disp, 0, &args, sizeof(args));
-               nvif_mthd(disp->disp, 0, &link, sizeof(link));
+       if (!mode) {
+               nv_encoder->ctrl &= ~BIT(head);
+               if (!(nv_encoder->ctrl & 0x0000000f))
+                       nv_encoder->ctrl = 0;
        } else {
-               nvif_mthd(disp->disp, 0, &args, sizeof(args));
+               nv_encoder->ctrl |= proto << 8;
+               nv_encoder->ctrl |= BIT(head);
        }
-}
 
-static void
-nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
-{
-       struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
-       u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
-       if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
-               if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
+       if ((push = evo_wait(core, 6))) {
+               if (core->base.user.oclass < GF110_DISP_CORE_CHANNEL_DMA) {
+                       if (mode) {
+                               if (mode->flags & DRM_MODE_FLAG_NHSYNC)
+                                       nv_encoder->ctrl |= 0x00001000;
+                               if (mode->flags & DRM_MODE_FLAG_NVSYNC)
+                                       nv_encoder->ctrl |= 0x00002000;
+                               nv_encoder->ctrl |= depth << 16;
+                       }
                        evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
-                       evo_data(push, (nv_encoder->ctrl = temp));
                } else {
+                       if (mode) {
+                               u32 magic = 0x31ec6000 | (head << 25);
+                               u32 syncs = 0x00000001;
+                               if (mode->flags & DRM_MODE_FLAG_NHSYNC)
+                                       syncs |= 0x00000008;
+                               if (mode->flags & DRM_MODE_FLAG_NVSYNC)
+                                       syncs |= 0x00000010;
+                               if (mode->flags & DRM_MODE_FLAG_INTERLACE)
+                                       magic |= 0x00000001;
+
+                               evo_mthd(push, 0x0404 + (head * 0x300), 2);
+                               evo_data(push, syncs | (depth << 6));
+                               evo_data(push, magic);
+                       }
                        evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
-                       evo_data(push, (nv_encoder->ctrl = temp));
                }
-               evo_kick(push, mast);
+               evo_data(push, nv_encoder->ctrl);
+               evo_kick(push, core);
        }
 }
 
@@ -3561,7 +3508,6 @@ nv50_sor_disable(struct drm_encoder *encoder)
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
        struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
 
-       nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
        nv_encoder->crtc = NULL;
 
        if (nv_crtc) {
@@ -3577,7 +3523,7 @@ nv50_sor_disable(struct drm_encoder *encoder)
                        }
                }
 
-               nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
+               nv_encoder->update(nv_encoder, nv_crtc->index, NULL, 0, 0);
                nv50_audio_disable(encoder, nv_crtc);
                nv50_hdmi_disable(&nv_encoder->base.base, nv_crtc);
        }
@@ -3599,13 +3545,10 @@ nv50_sor_enable(struct drm_encoder *encoder)
                .base.hashm   = nv_encoder->dcb->hashm,
        };
        struct nv50_disp *disp = nv50_disp(encoder->dev);
-       struct nv50_mast *mast = nv50_mast(encoder->dev);
        struct drm_device *dev = encoder->dev;
        struct nouveau_drm *drm = nouveau_drm(dev);
        struct nouveau_connector *nv_connector;
        struct nvbios *bios = &drm->vbios;
-       u32 mask, ctrl;
-       u8 owner = 1 << nv_crtc->index;
        u8 proto = 0xf;
        u8 depth = 0x0;
 
@@ -3684,38 +3627,7 @@ nv50_sor_enable(struct drm_encoder *encoder)
                break;
        }
 
-       if (nv50_vers(mast) >= GF110_DISP) {
-               u32 *push = evo_wait(mast, 3);
-               if (push) {
-                       u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
-                       u32 syncs = 0x00000001;
-
-                       if (mode->flags & DRM_MODE_FLAG_NHSYNC)
-                               syncs |= 0x00000008;
-                       if (mode->flags & DRM_MODE_FLAG_NVSYNC)
-                               syncs |= 0x00000010;
-
-                       if (mode->flags & DRM_MODE_FLAG_INTERLACE)
-                               magic |= 0x00000001;
-
-                       evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
-                       evo_data(push, syncs | (depth << 6));
-                       evo_data(push, magic);
-                       evo_kick(push, mast);
-               }
-
-               ctrl = proto << 8;
-               mask = 0x00000f00;
-       } else {
-               ctrl = (depth << 16) | (proto << 8);
-               if (mode->flags & DRM_MODE_FLAG_NHSYNC)
-                       ctrl |= 0x00001000;
-               if (mode->flags & DRM_MODE_FLAG_NVSYNC)
-                       ctrl |= 0x00002000;
-               mask = 0x000f3f00;
-       }
-
-       nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
+       nv_encoder->update(nv_encoder, nv_crtc->index, mode, proto, depth);
 }
 
 static const struct drm_encoder_helper_funcs
@@ -3724,7 +3636,6 @@ nv50_sor_help = {
        .atomic_check = nv50_outp_atomic_check,
        .enable = nv50_sor_enable,
        .disable = nv50_sor_disable,
-       .get_crtc = nv50_display_crtc_get,
 };
 
 static void
@@ -3765,7 +3676,7 @@ nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
                return -ENOMEM;
        nv_encoder->dcb = dcbe;
        nv_encoder->or = ffs(dcbe->or) - 1;
-       nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
+       nv_encoder->update = nv50_sor_update;
 
        encoder = to_drm_encoder(nv_encoder);
        encoder->possible_crtcs = dcbe->heads;
@@ -3913,7 +3824,6 @@ nv50_pior_help = {
        .atomic_check = nv50_pior_atomic_check,
        .enable = nv50_pior_enable,
        .disable = nv50_pior_disable,
-       .get_crtc = nv50_display_crtc_get,
 };
 
 static void
@@ -3974,67 +3884,6 @@ nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
        return 0;
 }
 
-/******************************************************************************
- * Framebuffer
- *****************************************************************************/
-
-static void
-nv50_fb_dtor(struct drm_framebuffer *fb)
-{
-}
-
-static int
-nv50_fb_ctor(struct drm_framebuffer *fb)
-{
-       struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
-       struct nouveau_drm *drm = nouveau_drm(fb->dev);
-       struct nouveau_bo *nvbo = nv_fb->nvbo;
-       struct nv50_disp *disp = nv50_disp(fb->dev);
-       u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
-       u8 tile = nvbo->tile_mode;
-       struct drm_crtc *crtc;
-
-       if (drm->device.info.chipset >= 0xc0)
-               tile >>= 4; /* yep.. */
-
-       switch (fb->depth) {
-       case  8: nv_fb->r_format = 0x1e00; break;
-       case 15: nv_fb->r_format = 0xe900; break;
-       case 16: nv_fb->r_format = 0xe800; break;
-       case 24:
-       case 32: nv_fb->r_format = 0xcf00; break;
-       case 30: nv_fb->r_format = 0xd100; break;
-       default:
-                NV_ERROR(drm, "unknown depth %d\n", fb->depth);
-                return -EINVAL;
-       }
-
-       if (disp->disp->oclass < G82_DISP) {
-               nv_fb->r_pitch   = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
-                                           (fb->pitches[0] | 0x00100000);
-               nv_fb->r_format |= kind << 16;
-       } else
-       if (disp->disp->oclass < GF110_DISP) {
-               nv_fb->r_pitch  = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
-                                          (fb->pitches[0] | 0x00100000);
-       } else {
-               nv_fb->r_pitch  = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
-                                          (fb->pitches[0] | 0x01000000);
-       }
-       nv_fb->r_handle = 0xffff0000 | kind;
-
-       list_for_each_entry(crtc, &drm->dev->mode_config.crtc_list, head) {
-               struct nv50_wndw *wndw = nv50_wndw(crtc->primary);
-               struct nv50_dmac_ctxdma *ctxdma;
-
-               ctxdma = nv50_dmac_ctxdma_new(wndw->dmac, nv_fb->r_handle, nv_fb);
-               if (IS_ERR(ctxdma))
-                       return PTR_ERR(ctxdma);
-       }
-
-       return 0;
-}
-
 /******************************************************************************
  * Atomic
  *****************************************************************************/
@@ -4044,10 +3893,20 @@ nv50_disp_atomic_commit_core(struct nouveau_drm *drm, u32 interlock)
 {
        struct nv50_disp *disp = nv50_disp(drm->dev);
        struct nv50_dmac *core = &disp->mast.base;
+       struct nv50_mstm *mstm;
+       struct drm_encoder *encoder;
        u32 *push;
 
        NV_ATOMIC(drm, "commit core %08x\n", interlock);
 
+       drm_for_each_encoder(encoder, drm->dev) {
+               if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
+                       mstm = nouveau_encoder(encoder)->dp.mstm;
+                       if (mstm && mstm->modified)
+                               nv50_mstm_prepare(mstm);
+               }
+       }
+
        if ((push = evo_wait(core, 5))) {
                evo_mthd(push, 0x0084, 1);
                evo_data(push, 0x80000000);
@@ -4063,6 +3922,14 @@ nv50_disp_atomic_commit_core(struct nouveau_drm *drm, u32 interlock)
                ) < 0)
                        NV_ERROR(drm, "EVO timeout\n");
        }
+
+       drm_for_each_encoder(encoder, drm->dev) {
+               if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
+                       mstm = nouveau_encoder(encoder)->dp.mstm;
+                       if (mstm && mstm->modified)
+                               nv50_mstm_cleanup(mstm);
+               }
+       }
 }
 
 static void
@@ -4226,6 +4093,8 @@ nv50_disp_atomic_commit_tail(struct drm_atomic_state *state)
        for_each_crtc_in_state(state, crtc, crtc_state, i) {
                if (crtc->state->event) {
                        unsigned long flags;
+                       /* Get correct count/ts if racing with vblank irq */
+                       drm_accurate_vblank_count(crtc);
                        spin_lock_irqsave(&crtc->dev->event_lock, flags);
                        drm_crtc_send_vblank_event(crtc, crtc->state->event);
                        spin_unlock_irqrestore(&crtc->dev->event_lock, flags);
@@ -4472,6 +4341,8 @@ nv50_disp_func = {
 void
 nv50_display_fini(struct drm_device *dev)
 {
+       struct nouveau_encoder *nv_encoder;
+       struct drm_encoder *encoder;
        struct drm_plane *plane;
 
        drm_for_each_plane(plane, dev) {
@@ -4480,12 +4351,18 @@ nv50_display_fini(struct drm_device *dev)
                        continue;
                nv50_wndw_fini(wndw);
        }
+
+       list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
+               if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) {
+                       nv_encoder = nouveau_encoder(encoder);
+                       nv50_mstm_fini(nv_encoder->dp.mstm);
+               }
+       }
 }
 
 int
 nv50_display_init(struct drm_device *dev)
 {
-       struct nv50_disp *disp = nv50_disp(dev);
        struct drm_encoder *encoder;
        struct drm_plane *plane;
        struct drm_crtc *crtc;
@@ -4495,13 +4372,6 @@ nv50_display_init(struct drm_device *dev)
        if (!push)
                return -EBUSY;
 
-       list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
-               struct nv50_wndw *wndw = &nv50_head(crtc)->_base->wndw;
-
-               nv50_crtc_lut_load(crtc);
-               nouveau_bo_wr32(disp->sync, wndw->sema / 4, wndw->data);
-       }
-
        evo_mthd(push, 0x0088, 1);
        evo_data(push, nv50_mast(dev)->base.sync.handle);
        evo_kick(push, nv50_mast(dev));
@@ -4512,18 +4382,18 @@ nv50_display_init(struct drm_device *dev)
                        struct nouveau_encoder *nv_encoder;
 
                        nv_encoder = nouveau_encoder(encoder);
-                       if (nv_encoder->dcb->type == DCB_OUTPUT_DP)
-                               nv_encoder->dcb->type = DCB_OUTPUT_EOL;
-
                        help = encoder->helper_private;
                        if (help && help->dpms)
                                help->dpms(encoder, DRM_MODE_DPMS_ON);
 
-                       if (nv_encoder->dcb->type == DCB_OUTPUT_EOL)
-                               nv_encoder->dcb->type = DCB_OUTPUT_DP;
+                       nv50_mstm_init(nv_encoder->dp.mstm);
                }
        }
 
+       drm_for_each_crtc(crtc, dev) {
+               nv50_head_lut_load(crtc);
+       }
+
        drm_for_each_plane(plane, dev) {
                struct nv50_wndw *wndw = nv50_wndw(plane);
                if (plane->funcs != &nv50_wndw)
@@ -4575,8 +4445,6 @@ nv50_display_create(struct drm_device *dev)
        nouveau_display(dev)->dtor = nv50_display_destroy;
        nouveau_display(dev)->init = nv50_display_init;
        nouveau_display(dev)->fini = nv50_display_fini;
-       nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
-       nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
        disp->disp = &nouveau_display(dev)->disp;
        dev->mode_config.funcs = &nv50_disp_func;
        if (nouveau_atomic)
@@ -4612,7 +4480,7 @@ nv50_display_create(struct drm_device *dev)
                crtcs = 2;
 
        for (i = 0; i < crtcs; i++) {
-               ret = nv50_crtc_create(dev, i);
+               ret = nv50_head_create(dev, i);
                if (ret)
                        goto out;
        }