drm/vc4: plane: Move additional planes creation to driver
authorMaxime Ripard <maxime@cerno.tech>
Thu, 6 Feb 2020 13:41:41 +0000 (14:41 +0100)
committerMaxime Ripard <maxime@cerno.tech>
Wed, 10 Jun 2020 09:09:38 +0000 (11:09 +0200)
So far the plane creation was done when each CRTC was bound, and those
planes were only tied to the CRTC that was registering them.

This causes two main issues:
  - The planes in the vc4 hardware are actually not tied to any CRTC, but
    can be used with every combination

  - More importantly, so far, we allocate 10 planes per CRTC, with 3 CRTCs.
    However, the next generation of hardware will have 5 CRTCs, putting us
    well above the maximum of 32 planes currently allowed by DRM.

This patch is the first one in a series of patches that will take down both
of these issues so that we can support the next generation of hardware
while keeping a good amount of planes.

We start by changing the way the planes are registered to first registering
the primary planes for each CRTC in the CRTC bind function as we used to,
but moving the overlay and cursor creation to the main driver bind
function, after all the CRTCs have been bound, and make the planes
associated to all CRTCs.

This will slightly change the ID order of the planes, since the primary
planes of all CRTCs will be first, and then a pattern of 8 overlays, 1
cursor plane for each CRTC.

This shouldn't cause any trouble since the ordering between the planes is
preserved though.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://patchwork.freedesktop.org/patch/msgid/0b85a3fdb20bb4ff85fb62cabd082d5a65e2730b.1590594512.git-series.maxime@cerno.tech
drivers/gpu/drm/vc4/vc4_crtc.c
drivers/gpu/drm/vc4/vc4_drv.c
drivers/gpu/drm/vc4/vc4_drv.h
drivers/gpu/drm/vc4/vc4_plane.c

index 63560eb..440ff63 100644 (file)
@@ -1178,10 +1178,6 @@ static int vc4_crtc_bind(struct device *dev, struct device *master, void *data)
         */
        drm_crtc_enable_color_mgmt(crtc, 0, true, crtc->gamma_size);
 
-       ret = vc4_plane_create_additional_planes(drm, crtc);
-       if (ret)
-               goto err_destroy_planes;
-
        vc4_crtc_get_cob_allocation(vc4_crtc);
 
        CRTC_WRITE(PV_INTEN, 0);
index 76f93b6..7792c97 100644 (file)
@@ -288,6 +288,10 @@ static int vc4_drm_bind(struct device *dev)
        if (ret)
                goto gem_destroy;
 
+       ret = vc4_plane_create_additional_planes(drm);
+       if (ret)
+               goto unbind_all;
+
        drm_fb_helper_remove_conflicting_framebuffers(NULL, "vc4drmfb", false);
 
        ret = vc4_kms_load(drm);
index bb3416e..528238a 100644 (file)
@@ -846,8 +846,7 @@ int vc4_kms_load(struct drm_device *dev);
 /* vc4_plane.c */
 struct drm_plane *vc4_plane_init(struct drm_device *dev,
                                 enum drm_plane_type type);
-int vc4_plane_create_additional_planes(struct drm_device *dev,
-                                      struct drm_crtc *crtc);
+int vc4_plane_create_additional_planes(struct drm_device *dev);
 u32 vc4_plane_write_dlist(struct drm_plane *plane, u32 __iomem *dlist);
 u32 vc4_plane_dlist_size(const struct drm_plane_state *state);
 void vc4_plane_async_set_fb(struct drm_plane *plane,
index ea559b3..d040d9f 100644 (file)
@@ -1268,10 +1268,10 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev,
        return plane;
 }
 
-int vc4_plane_create_additional_planes(struct drm_device *drm,
-                                      struct drm_crtc *crtc)
+int vc4_plane_create_additional_planes(struct drm_device *drm)
 {
        struct drm_plane *cursor_plane;
+       struct drm_crtc *crtc;
        unsigned int i;
 
        /* Set up some arbitrary number of planes.  We're not limited
@@ -1290,17 +1290,20 @@ int vc4_plane_create_additional_planes(struct drm_device *drm,
                if (IS_ERR(plane))
                        continue;
 
-               plane->possible_crtcs = drm_crtc_mask(crtc);
+               plane->possible_crtcs =
+                       GENMASK(drm->mode_config.num_crtc - 1, 0);
        }
 
-       /* Set up the legacy cursor after overlay initialization,
-        * since we overlay planes on the CRTC in the order they were
-        * initialized.
-        */
-       cursor_plane = vc4_plane_init(drm, DRM_PLANE_TYPE_CURSOR);
-       if (!IS_ERR(cursor_plane)) {
-               cursor_plane->possible_crtcs = drm_crtc_mask(crtc);
-               crtc->cursor = cursor_plane;
+       drm_for_each_crtc(crtc, drm) {
+               /* Set up the legacy cursor after overlay initialization,
+                * since we overlay planes on the CRTC in the order they were
+                * initialized.
+                */
+               cursor_plane = vc4_plane_init(drm, DRM_PLANE_TYPE_CURSOR);
+               if (!IS_ERR(cursor_plane)) {
+                       cursor_plane->possible_crtcs = drm_crtc_mask(crtc);
+                       crtc->cursor = cursor_plane;
+               }
        }
 
        return 0;