drm/dp: Split drm_dp_mst_allocate_vcpi
authorPandiyan, Dhinakaran <dhinakaran.pandiyan@intel.com>
Thu, 16 Mar 2017 07:10:26 +0000 (00:10 -0700)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 22 Mar 2017 20:47:44 +0000 (21:47 +0100)
drm_dp_mst_allocate_vcpi() apart from setting up the vcpi structure,
also finds if there are enough slots available. This check is a duplicate
of that implemented in drm_dp_mst_find_vcpi_slots(). Let's move this check
out and reuse the existing drm_dp_mst_find_vcpi_slots() function to check
if there are enough vcpi slots before allocating them.

This brings the check to one place. Additionally drivers that will use MST
state tracking for atomic modesets can use the atomic version of
find_vcpi_slots() and reuse drm_dp_mst_allocate_vcpi()

Signed-off-by: Dhinakaran Pandiyan <dhinakaran.pandiyan@intel.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1489648231-30700-4-git-send-email-dhinakaran.pandiyan@intel.com
drivers/gpu/drm/drm_dp_mst_topology.c
drivers/gpu/drm/i915/intel_dp_mst.c
drivers/gpu/drm/nouveau/nv50_display.c
drivers/gpu/drm/radeon/radeon_dp_mst.c
include/drm/drm_dp_mst_helper.h

index 2e2af13f70d5241812fe44edaeb57d902f88f8a6..d3fc7e4e85b7413eb586256540467cbd25f6090d 100644 (file)
@@ -2479,20 +2479,17 @@ int drm_dp_find_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr,
 EXPORT_SYMBOL(drm_dp_find_vcpi_slots);
 
 static int drm_dp_init_vcpi(struct drm_dp_mst_topology_mgr *mgr,
-                           struct drm_dp_vcpi *vcpi, int pbn)
+                           struct drm_dp_vcpi *vcpi, int pbn, int slots)
 {
-       int num_slots;
        int ret;
 
-       num_slots = DIV_ROUND_UP(pbn, mgr->pbn_div);
-
        /* max. time slots - one slot for MTP header */
-       if (num_slots > 63)
+       if (slots > 63)
                return -ENOSPC;
 
        vcpi->pbn = pbn;
-       vcpi->aligned_pbn = num_slots * mgr->pbn_div;
-       vcpi->num_slots = num_slots;
+       vcpi->aligned_pbn = slots * mgr->pbn_div;
+       vcpi->num_slots = slots;
 
        ret = drm_dp_mst_assign_payload_id(mgr, vcpi);
        if (ret < 0)
@@ -2507,7 +2504,8 @@ static int drm_dp_init_vcpi(struct drm_dp_mst_topology_mgr *mgr,
  * @pbn: payload bandwidth number to request
  * @slots: returned number of slots for this PBN.
  */
-bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn, int *slots)
+bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
+                             struct drm_dp_mst_port *port, int pbn, int slots)
 {
        int ret;
 
@@ -2515,16 +2513,18 @@ bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp
        if (!port)
                return false;
 
+       if (slots < 0)
+               return false;
+
        if (port->vcpi.vcpi > 0) {
                DRM_DEBUG_KMS("payload: vcpi %d already allocated for pbn %d - requested pbn %d\n", port->vcpi.vcpi, port->vcpi.pbn, pbn);
                if (pbn == port->vcpi.pbn) {
-                       *slots = port->vcpi.num_slots;
                        drm_dp_put_port(port);
                        return true;
                }
        }
 
-       ret = drm_dp_init_vcpi(mgr, &port->vcpi, pbn);
+       ret = drm_dp_init_vcpi(mgr, &port->vcpi, pbn, slots);
        if (ret) {
                DRM_DEBUG_KMS("failed to init vcpi slots=%d max=63 ret=%d\n",
                                DIV_ROUND_UP(pbn, mgr->pbn_div), ret);
@@ -2532,7 +2532,6 @@ bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp
        }
        DRM_DEBUG_KMS("initing vcpi for pbn=%d slots=%d\n",
                        pbn, port->vcpi.num_slots);
-       *slots = port->vcpi.num_slots;
 
        drm_dp_put_port(port);
        return true;
index 38e3ca2f6f180916663656280be27b23bd8b0a4f..f51574f7f160a95800406638ad55165a17a695d4 100644 (file)
@@ -147,7 +147,6 @@ static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
                to_intel_connector(conn_state->connector);
        int ret;
        uint32_t temp;
-       int slots;
 
        /* MST encoders are bound to a crtc, not to a connector,
         * force the mapping here for get_hw_state.
@@ -177,7 +176,8 @@ static void intel_mst_pre_enable_dp(struct intel_encoder *encoder,
 
        ret = drm_dp_mst_allocate_vcpi(&intel_dp->mst_mgr,
                                       connector->port,
-                                      pipe_config->pbn, &slots);
+                                      pipe_config->pbn,
+                                      pipe_config->dp_m_n.tu);
        if (ret == false) {
                DRM_ERROR("failed to allocate vcpi\n");
                return;
index 16915c29ec52e7bbe27b8da38e1274771451be5e..a58c53639c18efc0a647f8073258ac19d04eff3d 100644 (file)
@@ -2895,7 +2895,8 @@ nv50_msto_enable(struct drm_encoder *encoder)
        if (WARN_ON(!mstc))
                return;
 
-       r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, &slots);
+       slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn);
+       r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, slots);
        WARN_ON(!r);
 
        if (mstm->outp->dcb->sorconf.link & 1)
index 7d5ada3980dc80d012813078b161f371557002c5..6598306dca9b87b5a508e921c7e008e9ec43167a 100644 (file)
@@ -453,9 +453,11 @@ radeon_mst_encoder_dpms(struct drm_encoder *encoder, int mode)
                DRM_DEBUG_KMS("dig encoder is %d %d %d\n", dig_enc->dig_encoder,
                              dig_enc->linkb, radeon_crtc->crtc_id);
 
+               slots = drm_dp_find_vcpi_slots(&radeon_connector->mst_port->mst_mgr,
+                                              mst_enc->pbn);
                ret = drm_dp_mst_allocate_vcpi(&radeon_connector->mst_port->mst_mgr,
                                               radeon_connector->port,
-                                              mst_enc->pbn, &slots);
+                                              mst_enc->pbn, slots);
                ret = drm_dp_update_payload_part1(&radeon_connector->mst_port->mst_mgr);
 
                radeon_dp_mst_set_be_cntl(primary, mst_enc,
index d8365110eb2340c2bf936fc9f8524ede12e0a1e9..5b024764666c2b2b82cdc66fb7a1171417fc1def 100644 (file)
@@ -567,7 +567,8 @@ struct edid *drm_dp_mst_get_edid(struct drm_connector *connector, struct drm_dp_
 int drm_dp_calc_pbn_mode(int clock, int bpp);
 
 
-bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port, int pbn, int *slots);
+bool drm_dp_mst_allocate_vcpi(struct drm_dp_mst_topology_mgr *mgr,
+                             struct drm_dp_mst_port *port, int pbn, int slots);
 
 int drm_dp_mst_get_vcpi_slots(struct drm_dp_mst_topology_mgr *mgr, struct drm_dp_mst_port *port);