drm/nouveau/disp: replace hda func pointer check with flag
authorBen Skeggs <bskeggs@redhat.com>
Wed, 1 Jun 2022 10:46:28 +0000 (20:46 +1000)
committerDave Airlie <airlied@redhat.com>
Tue, 26 Jul 2022 23:05:47 +0000 (09:05 +1000)
Simpler, and less error-prone than a separate set of function pointers.

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
17 files changed:
drivers/gpu/drm/nouveau/nvkm/engine/disp/g84.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/g94.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/ga102.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gf119.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gk104.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gm107.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gm200.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gp100.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gt215.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/gv100.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/ior.h
drivers/gpu/drm/nouveau/nvkm/engine/disp/mcp77.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/mcp89.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/nv50.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c
drivers/gpu/drm/nouveau/nvkm/engine/disp/tu102.c

index af5d351..43dc73a 100644 (file)
@@ -109,7 +109,7 @@ g84_sor = {
 int
 g84_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&g84_sor, disp, SOR, id);
+       return nvkm_ior_new_(&g84_sor, disp, SOR, id, false);
 }
 
 static const struct nvkm_disp_mthd_list
index 5c9a769..92fefac 100644 (file)
@@ -298,7 +298,7 @@ g94_sor = {
 static int
 g94_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&g94_sor, disp, SOR, id);
+       return nvkm_ior_new_(&g94_sor, disp, SOR, id, false);
 }
 
 int
index c693ad0..9d008f0 100644 (file)
@@ -84,7 +84,7 @@ ga102_sor_clock(struct nvkm_ior *sor)
 }
 
 static const struct nvkm_ior_func
-ga102_sor_hda = {
+ga102_sor = {
        .route = {
                .get = gm200_sor_route_get,
                .set = gm200_sor_route_set,
@@ -114,40 +114,13 @@ ga102_sor_hda = {
        },
 };
 
-static const struct nvkm_ior_func
-ga102_sor = {
-       .route = {
-               .get = gm200_sor_route_get,
-               .set = gm200_sor_route_set,
-       },
-       .state = gv100_sor_state,
-       .power = nv50_sor_power,
-       .clock = ga102_sor_clock,
-       .hdmi = {
-               .ctrl = gv100_sor_hdmi_ctrl,
-               .scdc = gm200_sor_hdmi_scdc,
-       },
-       .dp = {
-               .lanes = { 0, 1, 2, 3 },
-               .links = ga102_sor_dp_links,
-               .power = g94_sor_dp_power,
-               .pattern = gm107_sor_dp_pattern,
-               .drive = gm200_sor_dp_drive,
-               .vcpi = tu102_sor_dp_vcpi,
-               .audio = gv100_sor_dp_audio,
-               .audio_sym = gv100_sor_dp_audio_sym,
-               .watermark = gv100_sor_dp_watermark,
-       },
-};
-
 static int
 ga102_sor_new(struct nvkm_disp *disp, int id)
 {
        struct nvkm_device *device = disp->engine.subdev.device;
        u32 hda = nvkm_rd32(device, 0x08a15c);
-       if (hda & BIT(id))
-               return nvkm_ior_new_(&ga102_sor_hda, disp, SOR, id);
-       return nvkm_ior_new_(&ga102_sor, disp, SOR, id);
+
+       return nvkm_ior_new_(&ga102_sor, disp, SOR, id, hda & BIT(id));
 }
 
 static const struct nvkm_disp_func
index 75b7b41..e6ebc72 100644 (file)
@@ -309,7 +309,7 @@ gf119_sor = {
 static int
 gf119_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&gf119_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gf119_sor, disp, SOR, id, true);
 }
 
 int
@@ -357,7 +357,7 @@ gf119_dac = {
 int
 gf119_dac_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&gf119_dac, disp, DAC, id);
+       return nvkm_ior_new_(&gf119_dac, disp, DAC, id, false);
 }
 
 int
index 1c9a5e0..b562a4d 100644 (file)
@@ -116,7 +116,7 @@ gk104_sor = {
 int
 gk104_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&gk104_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gk104_sor, disp, SOR, id, true);
 }
 
 static const struct nvkm_disp_mthd_list
index 301d7a9..0b25999 100644 (file)
@@ -81,7 +81,7 @@ gm107_sor = {
 static int
 gm107_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&gm107_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gm107_sor, disp, SOR, id, true);
 }
 
 static const struct nvkm_disp_func
index c65d85b..990f378 100644 (file)
@@ -110,7 +110,7 @@ gm200_sor_route_get(struct nvkm_outp *outp, int *link)
 }
 
 static const struct nvkm_ior_func
-gm200_sor_hda = {
+gm200_sor = {
        .route = {
                .get = gm200_sor_route_get,
                .set = gm200_sor_route_set,
@@ -140,32 +140,6 @@ gm200_sor_hda = {
        },
 };
 
-static const struct nvkm_ior_func
-gm200_sor = {
-       .route = {
-               .get = gm200_sor_route_get,
-               .set = gm200_sor_route_set,
-       },
-       .state = gf119_sor_state,
-       .power = nv50_sor_power,
-       .clock = gf119_sor_clock,
-       .hdmi = {
-               .ctrl = gk104_sor_hdmi_ctrl,
-               .scdc = gm200_sor_hdmi_scdc,
-       },
-       .dp = {
-               .lanes = { 0, 1, 2, 3 },
-               .links = gf119_sor_dp_links,
-               .power = g94_sor_dp_power,
-               .pattern = gm107_sor_dp_pattern,
-               .drive = gm200_sor_dp_drive,
-               .vcpi = gf119_sor_dp_vcpi,
-               .audio = gf119_sor_dp_audio,
-               .audio_sym = gf119_sor_dp_audio_sym,
-               .watermark = gf119_sor_dp_watermark,
-       },
-};
-
 static int
 gm200_sor_new(struct nvkm_disp *disp, int id)
 {
@@ -175,10 +149,7 @@ gm200_sor_new(struct nvkm_disp *disp, int id)
        if (!((hda = nvkm_rd32(device, 0x08a15c)) & 0x40000000))
                hda = nvkm_rd32(device, 0x101034);
 
-       if (hda & BIT(id))
-               return nvkm_ior_new_(&gm200_sor_hda, disp, SOR, id);
-
-       return nvkm_ior_new_(&gm200_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gm200_sor, disp, SOR, id, hda & BIT(id));
 }
 
 static const struct nvkm_disp_func
index 603b718..beec3c8 100644 (file)
@@ -29,7 +29,7 @@
 #include <nvif/class.h>
 
 static const struct nvkm_ior_func
-gp100_sor_hda = {
+gp100_sor = {
        .route = {
                .get = gm200_sor_route_get,
                .set = gm200_sor_route_set,
@@ -59,32 +59,6 @@ gp100_sor_hda = {
        },
 };
 
-static const struct nvkm_ior_func
-gp100_sor = {
-       .route = {
-               .get = gm200_sor_route_get,
-               .set = gm200_sor_route_set,
-       },
-       .state = gf119_sor_state,
-       .power = nv50_sor_power,
-       .clock = gf119_sor_clock,
-       .hdmi = {
-               .ctrl = gk104_sor_hdmi_ctrl,
-               .scdc = gm200_sor_hdmi_scdc,
-       },
-       .dp = {
-               .lanes = { 0, 1, 2, 3 },
-               .links = gf119_sor_dp_links,
-               .power = g94_sor_dp_power,
-               .pattern = gm107_sor_dp_pattern,
-               .drive = gm200_sor_dp_drive,
-               .vcpi = gf119_sor_dp_vcpi,
-               .audio = gf119_sor_dp_audio,
-               .audio_sym = gf119_sor_dp_audio_sym,
-               .watermark = gf119_sor_dp_watermark,
-       },
-};
-
 int
 gp100_sor_new(struct nvkm_disp *disp, int id)
 {
@@ -94,9 +68,7 @@ gp100_sor_new(struct nvkm_disp *disp, int id)
        if (!((hda = nvkm_rd32(device, 0x08a15c)) & 0x40000000))
                hda = nvkm_rd32(device, 0x10ebb0) >> 8;
 
-       if (hda & BIT(id))
-               return nvkm_ior_new_(&gp100_sor_hda, disp, SOR, id);
-       return nvkm_ior_new_(&gp100_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gp100_sor, disp, SOR, id, hda & BIT(id));
 }
 
 static const struct nvkm_disp_func
index 98d99e1..72a4c28 100644 (file)
@@ -168,7 +168,7 @@ gt215_sor = {
 static int
 gt215_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&gt215_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gt215_sor, disp, SOR, id, true);
 }
 
 static const struct nvkm_disp_func
index 18c40e3..aac1cdb 100644 (file)
@@ -165,7 +165,7 @@ gv100_sor_state(struct nvkm_ior *sor, struct nvkm_ior_state *state)
 }
 
 static const struct nvkm_ior_func
-gv100_sor_hda = {
+gv100_sor = {
        .route = {
                .get = gm200_sor_route_get,
                .set = gm200_sor_route_set,
@@ -194,31 +194,6 @@ gv100_sor_hda = {
        },
 };
 
-static const struct nvkm_ior_func
-gv100_sor = {
-       .route = {
-               .get = gm200_sor_route_get,
-               .set = gm200_sor_route_set,
-       },
-       .state = gv100_sor_state,
-       .power = nv50_sor_power,
-       .clock = gf119_sor_clock,
-       .hdmi = {
-               .ctrl = gv100_sor_hdmi_ctrl,
-               .scdc = gm200_sor_hdmi_scdc,
-       },
-       .dp = {
-               .lanes = { 0, 1, 2, 3 },
-               .links = gf119_sor_dp_links,
-               .power = g94_sor_dp_power,
-               .pattern = gm107_sor_dp_pattern,
-               .drive = gm200_sor_dp_drive,
-               .audio = gv100_sor_dp_audio,
-               .audio_sym = gv100_sor_dp_audio_sym,
-               .watermark = gv100_sor_dp_watermark,
-       },
-};
-
 static int
 gv100_sor_new(struct nvkm_disp *disp, int id)
 {
@@ -228,10 +203,7 @@ gv100_sor_new(struct nvkm_disp *disp, int id)
        if (!((hda = nvkm_rd32(device, 0x08a15c)) & 0x40000000))
                hda = nvkm_rd32(device, 0x118fb0) >> 8;
 
-       if (hda & BIT(id))
-               return nvkm_ior_new_(&gv100_sor_hda, disp, SOR, id);
-
-       return nvkm_ior_new_(&gv100_sor, disp, SOR, id);
+       return nvkm_ior_new_(&gv100_sor, disp, SOR, id, hda & BIT(id));
 }
 
 int
index 1963cc1..e420bf2 100644 (file)
@@ -55,7 +55,7 @@ nvkm_ior_del(struct nvkm_ior **pior)
 
 int
 nvkm_ior_new_(const struct nvkm_ior_func *func, struct nvkm_disp *disp,
-             enum nvkm_ior_type type, int id)
+             enum nvkm_ior_type type, int id, bool hda)
 {
        struct nvkm_ior *ior;
        if (!(ior = kzalloc(sizeof(*ior), GFP_KERNEL)))
@@ -64,6 +64,7 @@ nvkm_ior_new_(const struct nvkm_ior_func *func, struct nvkm_disp *disp,
        ior->disp = disp;
        ior->type = type;
        ior->id = id;
+       ior->hda = hda;
        snprintf(ior->name, sizeof(ior->name), "%s-%d", nvkm_ior_name[ior->type], ior->id);
        list_add_tail(&ior->head, &disp->iors);
        IOR_DBG(ior, "ctor");
index a8bd12a..d1e494e 100644 (file)
@@ -13,6 +13,7 @@ struct nvkm_ior {
                PIOR,
        } type;
        int id;
+       bool hda;
        char name[8];
 
        struct list_head head;
@@ -93,7 +94,7 @@ struct nvkm_ior_func {
 };
 
 int nvkm_ior_new_(const struct nvkm_ior_func *func, struct nvkm_disp *,
-                 enum nvkm_ior_type type, int id);
+                 enum nvkm_ior_type type, int id, bool hda);
 void nvkm_ior_del(struct nvkm_ior **);
 struct nvkm_ior *nvkm_ior_find(struct nvkm_disp *, enum nvkm_ior_type, int id);
 
index fb8bfb9..f0d23a6 100644 (file)
@@ -49,7 +49,7 @@ mcp77_sor = {
 static int
 mcp77_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&mcp77_sor, disp, SOR, id);
+       return nvkm_ior_new_(&mcp77_sor, disp, SOR, id, false);
 }
 
 static const struct nvkm_disp_func
index 8b9e976..25a1934 100644 (file)
@@ -54,7 +54,7 @@ mcp89_sor = {
 static int
 mcp89_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&mcp89_sor, disp, SOR, id);
+       return nvkm_ior_new_(&mcp89_sor, disp, SOR, id, true);
 }
 
 static const struct nvkm_disp_func
index 1a31515..a50239d 100644 (file)
@@ -147,7 +147,7 @@ nv50_pior = {
 int
 nv50_pior_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&nv50_pior, disp, PIOR, id);
+       return nvkm_ior_new_(&nv50_pior, disp, PIOR, id, false);
 }
 
 int
@@ -228,7 +228,7 @@ nv50_sor = {
 static int
 nv50_sor_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&nv50_sor, disp, SOR, id);
+       return nvkm_ior_new_(&nv50_sor, disp, SOR, id, false);
 }
 
 int
@@ -324,7 +324,7 @@ nv50_dac = {
 int
 nv50_dac_new(struct nvkm_disp *disp, int id)
 {
-       return nvkm_ior_new_(&nv50_dac, disp, DAC, id);
+       return nvkm_ior_new_(&nv50_dac, disp, DAC, id, false);
 }
 
 int
index f527adc..6094805 100644 (file)
@@ -120,7 +120,7 @@ nvkm_outp_acquire_hda(struct nvkm_outp *outp, enum nvkm_ior_type type,
 
        /* Failing that, a completely unused OR is the next best thing. */
        list_for_each_entry(ior, &outp->disp->iors, head) {
-               if (!ior->identity && !!ior->func->hda.hpd == hda &&
+               if (!ior->identity && ior->hda == hda &&
                    !ior->asy.outp && ior->type == type && !ior->arm.outp &&
                    (ior->func->route.set || ior->id == __ffs(outp->info.or)))
                        return nvkm_outp_acquire_ior(outp, user, ior);
@@ -130,7 +130,7 @@ nvkm_outp_acquire_hda(struct nvkm_outp *outp, enum nvkm_ior_type type,
         * but will be released during the next modeset.
         */
        list_for_each_entry(ior, &outp->disp->iors, head) {
-               if (!ior->identity && !!ior->func->hda.hpd == hda &&
+               if (!ior->identity && ior->hda == hda &&
                    !ior->asy.outp && ior->type == type &&
                    (ior->func->route.set || ior->id == __ffs(outp->info.or)))
                        return nvkm_outp_acquire_ior(outp, user, ior);
@@ -181,7 +181,7 @@ nvkm_outp_acquire(struct nvkm_outp *outp, u8 user, bool hda)
                         *
                         *     This warning is to make it obvious if that proves wrong.
                         */
-                       WARN_ON(hda && !ior->func->hda.hpd);
+                       WARN_ON(hda && !ior->hda);
                        return nvkm_outp_acquire_ior(outp, user, ior);
                }
        }
index b9cd706..febc909 100644 (file)
@@ -67,7 +67,7 @@ tu102_sor_dp_links(struct nvkm_ior *sor, struct nvkm_i2c_aux *aux)
 }
 
 static const struct nvkm_ior_func
-tu102_sor_hda = {
+tu102_sor = {
        .route = {
                .get = gm200_sor_route_get,
                .set = gm200_sor_route_set,
@@ -97,40 +97,13 @@ tu102_sor_hda = {
        },
 };
 
-static const struct nvkm_ior_func
-tu102_sor = {
-       .route = {
-               .get = gm200_sor_route_get,
-               .set = gm200_sor_route_set,
-       },
-       .state = gv100_sor_state,
-       .power = nv50_sor_power,
-       .clock = gf119_sor_clock,
-       .hdmi = {
-               .ctrl = gv100_sor_hdmi_ctrl,
-               .scdc = gm200_sor_hdmi_scdc,
-       },
-       .dp = {
-               .lanes = { 0, 1, 2, 3 },
-               .links = tu102_sor_dp_links,
-               .power = g94_sor_dp_power,
-               .pattern = gm107_sor_dp_pattern,
-               .drive = gm200_sor_dp_drive,
-               .vcpi = tu102_sor_dp_vcpi,
-               .audio = gv100_sor_dp_audio,
-               .audio_sym = gv100_sor_dp_audio_sym,
-               .watermark = gv100_sor_dp_watermark,
-       },
-};
-
 static int
 tu102_sor_new(struct nvkm_disp *disp, int id)
 {
        struct nvkm_device *device = disp->engine.subdev.device;
        u32 hda = nvkm_rd32(device, 0x08a15c);
-       if (hda & BIT(id))
-               return nvkm_ior_new_(&tu102_sor_hda, disp, SOR, id);
-       return nvkm_ior_new_(&tu102_sor, disp, SOR, id);
+
+       return nvkm_ior_new_(&tu102_sor, disp, SOR, id, hda & BIT(id));
 }
 
 int