drm/nouveau/disp: add dp mst id get/put methods
authorBen Skeggs <bskeggs@redhat.com>
Tue, 19 Sep 2023 21:56:30 +0000 (17:56 -0400)
committerLyude Paul <lyude@redhat.com>
Tue, 19 Sep 2023 22:22:22 +0000 (18:22 -0400)
- preparation for GSP-RM

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Acked-by: Danilo Krummrich <me@dakr.org>
Signed-off-by: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230919220442.202488-36-lyude@redhat.com
drivers/gpu/drm/nouveau/dispnv50/disp.c
drivers/gpu/drm/nouveau/dispnv50/head.h
drivers/gpu/drm/nouveau/dispnv50/headc57d.c
drivers/gpu/drm/nouveau/include/nvif/if0012.h
drivers/gpu/drm/nouveau/include/nvif/outp.h
drivers/gpu/drm/nouveau/nvif/outp.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/dp.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/uoutp.c

index d8ed23ddd2e4c5d370b8e1f210dc91e3f7654390..d6de5ee89d543694343e0a9136e48dd56e8298c6 100644 (file)
@@ -869,6 +869,8 @@ struct nv50_msto {
        struct nv50_mstc *mstc;
        bool disabled;
        bool enabled;
+
+       u32 display_id;
 };
 
 struct nouveau_encoder *nv50_real_outp(struct drm_encoder *encoder)
@@ -897,10 +899,17 @@ nv50_msto_cleanup(struct drm_atomic_state *state,
                drm_atomic_get_old_mst_topology_state(state, mgr);
        const struct drm_dp_mst_atomic_payload *old_payload =
                drm_atomic_get_mst_payload_state(old_mst_state, msto->mstc->port);
+       struct nv50_mstc *mstc = msto->mstc;
+       struct nv50_mstm *mstm = mstc->mstm;
 
        NV_ATOMIC(drm, "%s: msto cleanup\n", msto->encoder.name);
 
        if (msto->disabled) {
+               if (msto->head->func->display_id) {
+                       nvif_outp_dp_mst_id_put(&mstm->outp->outp, msto->display_id);
+                       msto->display_id = 0;
+               }
+
                msto->mstc = NULL;
                msto->disabled = false;
                drm_dp_remove_payload_part2(mgr, new_mst_state, old_payload, new_payload);
@@ -1041,6 +1050,11 @@ nv50_msto_atomic_enable(struct drm_encoder *encoder, struct drm_atomic_state *st
                nouveau_dp_train(mstm->outp, true, 0, 0);
        }
 
+       if (head->func->display_id) {
+               if (!WARN_ON(nvif_outp_dp_mst_id_get(&mstm->outp->outp, &msto->display_id)))
+                       head->func->display_id(head, msto->display_id);
+       }
+
        if (mstm->outp->outp.or.link & 1)
                proto = NV917D_SOR_SET_CONTROL_PROTOCOL_DP_A;
        else
@@ -1061,6 +1075,9 @@ nv50_msto_atomic_disable(struct drm_encoder *encoder, struct drm_atomic_state *s
        struct nv50_mstc *mstc = msto->mstc;
        struct nv50_mstm *mstm = mstc->mstm;
 
+       if (msto->head->func->display_id)
+               msto->head->func->display_id(msto->head, 0);
+
        mstm->outp->update(mstm->outp, msto->head->base.index, NULL, 0, 0);
        mstm->modified = true;
        if (!--mstm->links)
@@ -1544,7 +1561,7 @@ static void
 nv50_sor_atomic_disable(struct drm_encoder *encoder, struct drm_atomic_state *state)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
-       struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
+       struct nv50_head *head = nv50_head(nv_encoder->crtc);
        struct nouveau_connector *nv_connector = nv50_outp_get_old_connector(state, nv_encoder);
 #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
        struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev);
@@ -1563,7 +1580,7 @@ nv50_sor_atomic_disable(struct drm_encoder *encoder, struct drm_atomic_state *st
 #endif
 
        if (nv_encoder->dcb->type == DCB_OUTPUT_TMDS && nv_encoder->hdmi.enabled) {
-               nvif_outp_hdmi(&nv_encoder->outp, nv_crtc->index,
+               nvif_outp_hdmi(&nv_encoder->outp, head->base.index,
                               false, 0, 0, 0, false, false, false);
                nv_encoder->hdmi.enabled = false;
        }
@@ -1571,8 +1588,11 @@ nv50_sor_atomic_disable(struct drm_encoder *encoder, struct drm_atomic_state *st
        if (nv_encoder->dcb->type == DCB_OUTPUT_DP)
                nouveau_dp_power_down(nv_encoder);
 
-       nv_encoder->update(nv_encoder, nv_crtc->index, NULL, 0, 0);
-       nv50_audio_disable(encoder, nv_crtc);
+       if (head->func->display_id)
+               head->func->display_id(head, 0);
+
+       nv_encoder->update(nv_encoder, head->base.index, NULL, 0, 0);
+       nv50_audio_disable(encoder, &head->base);
        nv_encoder->crtc = NULL;
 }
 
@@ -1585,6 +1605,7 @@ nv50_sor_atomic_enable(struct drm_encoder *encoder, struct drm_atomic_state *sta
                nv50_head_atom(drm_atomic_get_new_crtc_state(state, &nv_crtc->base));
        struct drm_display_mode *mode = &asyh->state.adjusted_mode;
        struct nv50_disp *disp = nv50_disp(encoder->dev);
+       struct nv50_head *head = nv50_head(&nv_crtc->base);
        struct nvif_outp *outp = &nv_encoder->outp;
        struct drm_device *dev = encoder->dev;
        struct nouveau_drm *drm = nouveau_drm(dev);
@@ -1682,6 +1703,9 @@ nv50_sor_atomic_enable(struct drm_encoder *encoder, struct drm_atomic_state *sta
                break;
        }
 
+       if (head->func->display_id)
+               head->func->display_id(head, BIT(nv_encoder->dcb->id));
+
        nv_encoder->update(nv_encoder, nv_crtc->index, asyh, proto, depth);
 }
 
index 41c8788dfb3125e1e2cc9413fbe9ea9b2b65ed4f..e9d17037ffcfc494c0c3c463afa021e0a0bc4a33 100644 (file)
@@ -49,6 +49,7 @@ struct nv50_head_func {
        int (*procamp)(struct nv50_head *, struct nv50_head_atom *);
        int (*or)(struct nv50_head *, struct nv50_head_atom *);
        void (*static_wndw_map)(struct nv50_head *, struct nv50_head_atom *);
+       int (*display_id)(struct nv50_head *, u32 display_id);
 };
 
 extern const struct nv50_head_func head507d;
index 543f08ceaad6de28b9b47df3509a4978de46f531..53b1248c40ec838445f65ed831e275ad2883730f 100644 (file)
 
 #include <nvhw/class/clc57d.h>
 
+static int
+headc57d_display_id(struct nv50_head *head, u32 display_id)
+{
+       struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
+       int ret;
+
+       if ((ret = PUSH_WAIT(push, 2)))
+               return ret;
+
+       PUSH_NVSQ(push, NVC57D, 0x2020 + (head->base.index * 0x400), display_id);
+       return 0;
+}
+
 static int
 headc57d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
 {
@@ -250,4 +263,5 @@ headc57d = {
        .or = headc57d_or,
        /* TODO: flexible window mappings */
        .static_wndw_map = headc37d_static_wndw_map,
+       .display_id = headc57d_display_id,
 };
index 6fb297b65ae87b31020870c199a66b887810c73c..502f342e0d7759b12c118559cac1881952410fad 100644 (file)
@@ -37,6 +37,8 @@ union nvif_outp_args {
 #define NVIF_OUTP_V0_DP_TRAIN      0x73
 #define NVIF_OUTP_V0_DP_DRIVE      0x74
 #define NVIF_OUTP_V0_DP_SST        0x75
+#define NVIF_OUTP_V0_DP_MST_ID_GET 0x76
+#define NVIF_OUTP_V0_DP_MST_ID_PUT 0x77
 #define NVIF_OUTP_V0_DP_MST_VCPI   0x78
 
 union nvif_outp_detect_args {
@@ -234,6 +236,22 @@ union nvif_outp_dp_sst_args {
        } v0;
 };
 
+union nvif_outp_dp_mst_id_put_args {
+       struct nvif_outp_dp_mst_id_put_v0 {
+               __u8  version;
+               __u8  pad01[3];
+               __u32 id;
+       } v0;
+};
+
+union nvif_outp_dp_mst_id_get_args {
+       struct nvif_outp_dp_mst_id_get_v0 {
+               __u8  version;
+               __u8  pad01[3];
+               __u32 id;
+       } v0;
+};
+
 union nvif_outp_dp_mst_vcpi_args {
        struct nvif_outp_dp_mst_vcpi_v0 {
                __u8  version;
index 881cbed5f0ee346d254b0824c3952f1a180e0b8a..2d86838ed559863fac31985a614c9c3f01320e7f 100644 (file)
@@ -69,6 +69,8 @@ int nvif_outp_dp_train(struct nvif_outp *, u8 dpcd[DP_RECEIVER_CAP_SIZE],
                       bool retrain);
 int nvif_outp_dp_drive(struct nvif_outp *, u8 link_nr, u8 pe[4], u8 vs[4]);
 int nvif_outp_dp_sst(struct nvif_outp *, int head, u32 watermark, u32 hblanksym, u32 vblanksym);
+int nvif_outp_dp_mst_id_get(struct nvif_outp *, u32 *id);
+int nvif_outp_dp_mst_id_put(struct nvif_outp *, u32 id);
 int nvif_outp_dp_mst_vcpi(struct nvif_outp *, int head,
                          u8 start_slot, u8 num_slots, u16 pbn, u16 aligned_pbn);
 #endif
index 952103aa93b78b3338b5ce63053ed50e6ff6b037..97e5855c2cf54a8ded4193db54cd53b1d9f61265 100644 (file)
@@ -46,6 +46,35 @@ nvif_outp_dp_mst_vcpi(struct nvif_outp *outp, int head,
        return ret;
 }
 
+int
+nvif_outp_dp_mst_id_put(struct nvif_outp *outp, u32 id)
+{
+       struct nvif_outp_dp_mst_id_get_v0 args;
+       int ret;
+
+       args.version = 0;
+       args.id = id;
+       ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_MST_ID_PUT, &args, sizeof(args));
+       NVIF_ERRON(ret, &outp->object, "[DP_MST_ID_PUT id:%08x]", args.id);
+       return ret;
+}
+
+int
+nvif_outp_dp_mst_id_get(struct nvif_outp *outp, u32 *id)
+{
+       struct nvif_outp_dp_mst_id_get_v0 args;
+       int ret;
+
+       args.version = 0;
+       ret = nvif_object_mthd(&outp->object, NVIF_OUTP_V0_DP_MST_ID_GET, &args, sizeof(args));
+       NVIF_ERRON(ret, &outp->object, "[DP_MST_ID_GET] id:%08x", args.id);
+       if (ret)
+               return ret;
+
+       *id = args.id;
+       return 0;
+}
+
 int
 nvif_outp_dp_sst(struct nvif_outp *outp, int head, u32 watermark, u32 hblanksym, u32 vblanksym)
 {
index 77a91d42b977a75a8d8bec12fe649a1d8ed812bd..aaa7796946ceb30803836378f0e2689d7937ec53 100644 (file)
  */
 #define AMPERE_IED_HACK(disp) ((disp)->engine.subdev.device->card_type >= GA100)
 
+static int
+nvkm_dp_mst_id_put(struct nvkm_outp *outp, u32 id)
+{
+       return 0;
+}
+
+static int
+nvkm_dp_mst_id_get(struct nvkm_outp *outp, u32 *pid)
+{
+       *pid = BIT(outp->index);
+       return 0;
+}
+
 static int
 nvkm_dp_aux_xfer(struct nvkm_outp *outp, u8 type, u32 addr, u8 *data, u8 *size)
 {
@@ -614,6 +627,8 @@ nvkm_dp_func = {
        .dp.aux_xfer = nvkm_dp_aux_xfer,
        .dp.train = nvkm_dp_train,
        .dp.drive = nvkm_dp_drive,
+       .dp.mst_id_get = nvkm_dp_mst_id_get,
+       .dp.mst_id_put = nvkm_dp_mst_id_put,
 };
 
 int
index cda17941de89a3045f31439162a8337540835fd0..3ec7318d9144e5cfd4b453bfe9df9f412cde6a58 100644 (file)
@@ -109,6 +109,8 @@ struct nvkm_outp_func {
                int (*rates)(struct nvkm_outp *);
                int (*train)(struct nvkm_outp *, bool retrain);
                int (*drive)(struct nvkm_outp *, u8 lanes, u8 pe[4], u8 vs[4]);
+               int (*mst_id_get)(struct nvkm_outp *, u32 *id);
+               int (*mst_id_put)(struct nvkm_outp *, u32 id);
        } dp;
 };
 
index 225f88fbdae0ff4954ed1b3aeca7e7578eff4ad4..ad52d9ed594af618cceaaa68be3e4d7de51d3bcc 100644 (file)
@@ -45,6 +45,32 @@ nvkm_uoutp_mthd_dp_mst_vcpi(struct nvkm_outp *outp, void *argv, u32 argc)
        return 0;
 }
 
+static int
+nvkm_uoutp_mthd_dp_mst_id_put(struct nvkm_outp *outp, void *argv, u32 argc)
+{
+       union nvif_outp_dp_mst_id_put_args *args = argv;
+
+       if (argc != sizeof(args->v0) || args->v0.version != 0)
+               return -ENOSYS;
+       if (!outp->func->dp.mst_id_put)
+               return -EINVAL;
+
+       return outp->func->dp.mst_id_put(outp, args->v0.id);
+}
+
+static int
+nvkm_uoutp_mthd_dp_mst_id_get(struct nvkm_outp *outp, void *argv, u32 argc)
+{
+       union nvif_outp_dp_mst_id_get_args *args = argv;
+
+       if (argc != sizeof(args->v0) || args->v0.version != 0)
+               return -ENOSYS;
+       if (!outp->func->dp.mst_id_get)
+               return -EINVAL;
+
+       return outp->func->dp.mst_id_get(outp, &args->v0.id);
+}
+
 static int
 nvkm_uoutp_mthd_dp_sst(struct nvkm_outp *outp, void *argv, u32 argc)
 {
@@ -482,6 +508,8 @@ nvkm_uoutp_mthd_acquired(struct nvkm_outp *outp, u32 mthd, void *argv, u32 argc)
        case NVIF_OUTP_V0_DP_TRAIN     : return nvkm_uoutp_mthd_dp_train     (outp, argv, argc);
        case NVIF_OUTP_V0_DP_DRIVE     : return nvkm_uoutp_mthd_dp_drive     (outp, argv, argc);
        case NVIF_OUTP_V0_DP_SST       : return nvkm_uoutp_mthd_dp_sst       (outp, argv, argc);
+       case NVIF_OUTP_V0_DP_MST_ID_GET: return nvkm_uoutp_mthd_dp_mst_id_get(outp, argv, argc);
+       case NVIF_OUTP_V0_DP_MST_ID_PUT: return nvkm_uoutp_mthd_dp_mst_id_put(outp, argv, argc);
        case NVIF_OUTP_V0_DP_MST_VCPI  : return nvkm_uoutp_mthd_dp_mst_vcpi  (outp, argv, argc);
        default:
                break;