]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
drm/nouveau/disp: add output class
authorBen Skeggs <bskeggs@redhat.com>
Wed, 1 Jun 2022 10:46:31 +0000 (20:46 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 26 Jul 2022 23:05:49 +0000 (09:05 +1000)
Will be used to more cleanly implement existing method interfaces that
take some confusing (IEDTkey, inherited from VBIOS, which RM no longer
uses on Ampere) match values to determine which display path to operate
on.

Methods will be protected from racing with supervisor, and from being
called where they shouldn't be (ie. without an OR assigned).

v2:
- use ?: (lyude)
v3:
- fix return code if noacquire() method fails

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
17 files changed:
drivers/gpu/drm/nouveau/dispnv50/disp.c
drivers/gpu/drm/nouveau/include/nvif/class.h
drivers/gpu/drm/nouveau/include/nvif/disp.h
drivers/gpu/drm/nouveau/include/nvif/if0010.h
drivers/gpu/drm/nouveau/include/nvif/if0012.h [new file with mode: 0644]
drivers/gpu/drm/nouveau/include/nvif/outp.h [new file with mode: 0644]
drivers/gpu/drm/nouveau/include/nvkm/subdev/bios/dcb.h
drivers/gpu/drm/nouveau/nouveau_bios.c
drivers/gpu/drm/nouveau/nouveau_encoder.h
drivers/gpu/drm/nouveau/nvif/Kbuild
drivers/gpu/drm/nouveau/nvif/disp.c
drivers/gpu/drm/nouveau/nvif/outp.c [new file with mode: 0644]
drivers/gpu/drm/nouveau/nvkm/engine/disp/Kbuild
drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/priv.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/udisp.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/uoutp.c [new file with mode: 0644]

index f4d0bc362c89844ea63f302674a4a8709ed3c647..e094fb0741055bbb1aa8d3b864c19b08be6203d7 100644 (file)
@@ -563,6 +563,10 @@ nv50_dac_help = {
 static void
 nv50_dac_destroy(struct drm_encoder *encoder)
 {
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+
+       nvif_outp_dtor(&nv_encoder->outp);
+
        drm_encoder_cleanup(encoder);
        kfree(encoder);
 }
@@ -576,6 +580,7 @@ static int
 nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
 {
        struct nouveau_drm *drm = nouveau_drm(connector->dev);
+       struct nv50_disp *disp = nv50_disp(connector->dev);
        struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device);
        struct nvkm_i2c_bus *bus;
        struct nouveau_encoder *nv_encoder;
@@ -599,7 +604,7 @@ nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
        drm_encoder_helper_add(encoder, &nv50_dac_help);
 
        drm_connector_attach_encoder(connector, encoder);
-       return 0;
+       return nvif_outp_ctor(disp->disp, nv_encoder->base.base.name, dcbe->id, &nv_encoder->outp);
 }
 
 /*
@@ -1822,6 +1827,9 @@ static void
 nv50_sor_destroy(struct drm_encoder *encoder)
 {
        struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+
+       nvif_outp_dtor(&nv_encoder->outp);
+
        nv50_mstm_del(&nv_encoder->dp.mstm);
        drm_encoder_cleanup(encoder);
 
@@ -1918,7 +1926,7 @@ nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
                        nv_encoder->i2c = &bus->i2c;
        }
 
-       return 0;
+       return nvif_outp_ctor(disp->disp, nv_encoder->base.base.name, dcbe->id, &nv_encoder->outp);
 }
 
 /******************************************************************************
@@ -1999,6 +2007,10 @@ nv50_pior_help = {
 static void
 nv50_pior_destroy(struct drm_encoder *encoder)
 {
+       struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
+
+       nvif_outp_dtor(&nv_encoder->outp);
+
        drm_encoder_cleanup(encoder);
        kfree(encoder);
 }
@@ -2056,7 +2068,7 @@ nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
        disp->core->func->pior->get_caps(disp, nv_encoder, ffs(dcbe->or) - 1);
        nv50_outp_dump_caps(drm, nv_encoder);
 
-       return 0;
+       return nvif_outp_ctor(disp->disp, nv_encoder->base.base.name, dcbe->id, &nv_encoder->outp);
 }
 
 /******************************************************************************
index c7dab84e0a3023e7c728bf079bd77a12a5eabbea..8641db649f484f697176aaae84aa7535395c2938 100644 (file)
@@ -34,6 +34,7 @@
 
 #define NVIF_CLASS_DISP                              /* if0010.h */  0x80000010
 #define NVIF_CLASS_CONN                              /* if0011.h */  0x80000011
+#define NVIF_CLASS_OUTP                              /* if0012.h */  0x80000012
 #define NVIF_CLASS_DISP_CHAN                         /* if0014.h */  0x80000014
 
 /* the below match nvidia-assigned (either in hw, or sw) class numbers */
index a93055b781f2b8f12ccb69ce01a3cb988185591c..742632ad3bea971b0fa60e5c39e66276e9fd08ff 100644 (file)
@@ -6,6 +6,7 @@ struct nvif_device;
 struct nvif_disp {
        struct nvif_object object;
        unsigned long conn_mask;
+       unsigned long outp_mask;
 };
 
 int nvif_disp_ctor(struct nvif_device *, const char *name, s32 oclass,
index 3af495dbd4c67b3c94ad65d7ff2d00078a3d667a..fc236ef289654261b57256443bce507ad08e1da4 100644 (file)
@@ -7,6 +7,7 @@ union nvif_disp_args {
                __u8 version;
                __u8 pad01[3];
                __u32 conn_mask;
+               __u32 outp_mask;
        } v0;
 };
 #endif
diff --git a/drivers/gpu/drm/nouveau/include/nvif/if0012.h b/drivers/gpu/drm/nouveau/include/nvif/if0012.h
new file mode 100644 (file)
index 0000000..c0793e0
--- /dev/null
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVIF_IF0012_H__
+#define __NVIF_IF0012_H__
+
+union nvif_outp_args {
+       struct nvif_outp_v0 {
+               __u8 version;
+               __u8 id;        /* DCB device index. */
+               __u8 pad02[6];
+       } v0;
+};
+#endif
diff --git a/drivers/gpu/drm/nouveau/include/nvif/outp.h b/drivers/gpu/drm/nouveau/include/nvif/outp.h
new file mode 100644 (file)
index 0000000..64d2131
--- /dev/null
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __NVIF_OUTP_H__
+#define __NVIF_OUTP_H__
+#include <nvif/object.h>
+struct nvif_disp;
+
+struct nvif_outp {
+       struct nvif_object object;
+};
+
+int nvif_outp_ctor(struct nvif_disp *, const char *name, int id, struct nvif_outp *);
+void nvif_outp_dtor(struct nvif_outp *);
+#endif
index a27a0f3fe7aa098194f60b8d3a581dbf6a46a148..73f9d9947e7e80d66bcc86c13610006275e6fed5 100644 (file)
@@ -54,6 +54,7 @@ struct dcb_output {
                } tmdsconf;
        };
        bool i2c_upper_default;
+       int id;
 };
 
 u16 dcb_table(struct nvkm_bios *, u8 *ver, u8 *hdr, u8 *ent, u8 *len);
index 41b78e9ecd4e83ab6a31a630a4707d9ab3962d13..189903b65edc997d0250d9b39920f7654c105a0b 100644 (file)
@@ -1801,6 +1801,8 @@ parse_dcb_entry(struct drm_device *dev, void *data, int idx, u8 *outp)
                        ret = parse_dcb20_entry(dev, dcb, conn, conf, entry);
                else
                        ret = parse_dcb15_entry(dev, dcb, conn, conf, entry);
+               entry->id = idx;
+
                if (!ret)
                        return 1; /* stop parsing */
 
index c2f5f0cb70d5842de2ff15203dcd7d0cb6b10c85..b72e5783a00f3480a0e23b0ef4b4abdf2f091e2e 100644 (file)
@@ -26,7 +26,7 @@
 
 #ifndef __NOUVEAU_ENCODER_H__
 #define __NOUVEAU_ENCODER_H__
-
+#include <nvif/outp.h>
 #include <subdev/bios/dcb.h>
 
 #include <drm/display/drm_dp_helper.h>
@@ -46,6 +46,7 @@ struct nouveau_encoder {
        struct drm_encoder_slave base;
 
        struct dcb_output *dcb;
+       struct nvif_outp outp;
        int or;
        int link;
 
index 576237f47d8d9ed176610a6bedeff1b525180b28..6abc4bc42e355d7b7f08c5bdde56f25c93cc88c7 100644 (file)
@@ -9,6 +9,7 @@ nvif-y += nvif/fifo.o
 nvif-y += nvif/mem.o
 nvif-y += nvif/mmu.o
 nvif-y += nvif/notify.o
+nvif-y += nvif/outp.o
 nvif-y += nvif/timer.o
 nvif-y += nvif/vmm.o
 
index b8e98070c77edd5e58187520a8a6e3444e24a851..926b0c04b1e87586d22dadeabdd490d5e6707f06 100644 (file)
@@ -72,7 +72,9 @@ nvif_disp_ctor(struct nvif_device *device, const char *name, s32 oclass, struct
        if (ret)
                return ret;
 
-       NVIF_DEBUG(&disp->object, "[NEW] conn_mask:%08x", args.conn_mask);
+       NVIF_DEBUG(&disp->object, "[NEW] conn_mask:%08x outp_mask:%08x",
+                  args.conn_mask, args.outp_mask);
        disp->conn_mask = args.conn_mask;
+       disp->outp_mask = args.outp_mask;
        return 0;
 }
diff --git a/drivers/gpu/drm/nouveau/nvif/outp.c b/drivers/gpu/drm/nouveau/nvif/outp.c
new file mode 100644 (file)
index 0000000..5a231bf
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2021 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <nvif/outp.h>
+#include <nvif/disp.h>
+#include <nvif/printf.h>
+
+#include <nvif/class.h>
+#include <nvif/if0012.h>
+
+void
+nvif_outp_dtor(struct nvif_outp *outp)
+{
+       nvif_object_dtor(&outp->object);
+}
+
+int
+nvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp)
+{
+       struct nvif_outp_v0 args;
+       int ret;
+
+       args.version = 0;
+       args.id = id;
+
+       ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP,
+                              &args, sizeof(args), &outp->object);
+       NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id);
+       return ret;
+}
index a5accccf88eaf545b7f1c36ec28be4042818cd9a..600072a904bed45f5382ed060cd828957eda255c 100644 (file)
@@ -33,3 +33,4 @@ nvkm-y += nvkm/engine/disp/rootnv50.o
 
 nvkm-y += nvkm/engine/disp/udisp.o
 nvkm-y += nvkm/engine/disp/uconn.o
+nvkm-y += nvkm/engine/disp/uoutp.o
index a72c123e9ca5c9acbd97256665f03648171f0e1a..3f3924c4195710ca716cd99d496343725507cce2 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: MIT */
 #ifndef __NVKM_DISP_OUTP_H__
 #define __NVKM_DISP_OUTP_H__
-#include <engine/disp.h>
+#include "priv.h"
 #include <core/notify.h>
 
 #include <subdev/bios.h>
@@ -53,6 +53,8 @@ struct nvkm_outp {
                        } lt;
                } dp;
        };
+
+       struct nvkm_object object;
 };
 
 int nvkm_outp_new_(const struct nvkm_outp_func *, struct nvkm_disp *, int index,
index d023ca634c83e382fbb94c92996746c13265516d..cb25dfe849f0fb79f0cffa26c697d086ae5dc53f 100644 (file)
@@ -85,4 +85,5 @@ extern const struct nvkm_event_func gv100_disp_chan_uevent;
 
 int nvkm_udisp_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
 int nvkm_uconn_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
+int nvkm_uoutp_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
 #endif
index 82e052950a32bbeb99f21890c9fc27748f190208..0841e7ce03436d4d56950397a142dd8938e354d9 100644 (file)
@@ -21,6 +21,7 @@
  */
 #include "priv.h"
 #include "conn.h"
+#include "outp.h"
 
 #include <nvif/class.h>
 #include <nvif/if0010.h>
@@ -36,6 +37,12 @@ nvkm_udisp_sclass(struct nvkm_object *object, int index, struct nvkm_oclass *scl
                return 0;
        }
 
+       if (index-- == 0) {
+               sclass->base = (struct nvkm_sclass) { 0, 0, NVIF_CLASS_OUTP };
+               sclass->ctor = nvkm_uoutp_new;
+               return 0;
+       }
+
        if (disp->func->user[index].ctor) {
                sclass->base = disp->func->user[index].base;
                sclass->ctor = disp->func->user[index].ctor;
@@ -81,6 +88,7 @@ nvkm_udisp_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nv
 {
        struct nvkm_disp *disp = nvkm_disp(oclass->engine);
        struct nvkm_conn *conn;
+       struct nvkm_outp *outp;
        union nvif_disp_args *args = argv;
 
        if (argc != sizeof(args->v0) || args->v0.version != 0)
@@ -99,5 +107,9 @@ nvkm_udisp_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nv
        list_for_each_entry(conn, &disp->conns, head)
                args->v0.conn_mask |= BIT(conn->index);
 
+       args->v0.outp_mask = 0;
+       list_for_each_entry(outp, &disp->outps, head)
+               args->v0.outp_mask |= BIT(outp->index);
+
        return 0;
 }
diff --git a/drivers/gpu/drm/nouveau/nvkm/engine/disp/uoutp.c b/drivers/gpu/drm/nouveau/nvkm/engine/disp/uoutp.c
new file mode 100644 (file)
index 0000000..1ea144e
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2021 Red Hat Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+#define nvkm_uoutp(p) container_of((p), struct nvkm_outp, object)
+#include "outp.h"
+
+#include <nvif/if0012.h>
+
+static int
+nvkm_uoutp_mthd_noacquire(struct nvkm_outp *outp, u32 mthd, void *argv, u32 argc)
+{
+       switch (mthd) {
+       default:
+               break;
+       }
+
+       return 1;
+}
+
+static int
+nvkm_uoutp_mthd(struct nvkm_object *object, u32 mthd, void *argv, u32 argc)
+{
+       struct nvkm_outp *outp = nvkm_uoutp(object);
+       struct nvkm_disp *disp = outp->disp;
+       int ret;
+
+       mutex_lock(&disp->super.mutex);
+
+       ret = nvkm_uoutp_mthd_noacquire(outp, mthd, argv, argc);
+       if (ret <= 0)
+               goto done;
+
+done:
+       mutex_unlock(&disp->super.mutex);
+       return ret;
+}
+
+static void *
+nvkm_uoutp_dtor(struct nvkm_object *object)
+{
+       struct nvkm_outp *outp = nvkm_uoutp(object);
+       struct nvkm_disp *disp = outp->disp;
+
+       spin_lock(&disp->client.lock);
+       outp->object.func = NULL;
+       spin_unlock(&disp->client.lock);
+       return NULL;
+}
+
+static const struct nvkm_object_func
+nvkm_uoutp = {
+       .dtor = nvkm_uoutp_dtor,
+       .mthd = nvkm_uoutp_mthd,
+};
+
+int
+nvkm_uoutp_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nvkm_object **pobject)
+{
+       struct nvkm_disp *disp = nvkm_udisp(oclass->parent);
+       struct nvkm_outp *outt, *outp = NULL;
+       union nvif_outp_args *args = argv;
+       int ret;
+
+       if (argc != sizeof(args->v0) || args->v0.version != 0)
+               return -ENOSYS;
+
+       list_for_each_entry(outt, &disp->outps, head) {
+               if (outt->index == args->v0.id) {
+                       outp = outt;
+                       break;
+               }
+       }
+
+       if (!outp)
+               return -EINVAL;
+
+       ret = -EBUSY;
+       spin_lock(&disp->client.lock);
+       if (!outp->object.func) {
+               nvkm_object_ctor(&nvkm_uoutp, oclass, &outp->object);
+               *pobject = &outp->object;
+               ret = 0;
+       }
+       spin_unlock(&disp->client.lock);
+       return ret;
+}