Re: [PATCH v5] drm/msm/dpu: improve DSC allocation

2023-12-14 Thread Dmitry Baryshkov
On Thu, 14 Dec 2023 at 19:34, Kuogee Hsieh  wrote:
>
>
> On 12/13/2023 3:00 PM, Dmitry Baryshkov wrote:
> > On Wed, 13 Dec 2023 at 20:58, Kuogee Hsieh  wrote:
> >> At DSC V1.1 DCE (Display Compression Engine) contains a DSC encoder.
> >> However, at DSC V1.2 DCE consists of two DSC encoders, one has an odd
> >> index and another one has an even index. Each encoder can work
> >> independently. But only two DSC encoders from same DCE can be paired
> >> to work together to support DSC merge mode at DSC V1.2. For DSC V1.1
> >> two consecutive DSC encoders (start with even index) have to be paired
> >> to support DSC merge mode.  In addition, the DSC with even index have
> >> to be mapped to even PINGPONG index and DSC with odd index have to be
> >> mapped to odd PINGPONG index at its data path in regardless of DSC
> >> V1.1 or V1.2. This patch improves DSC allocation mechanism with
> >> consideration of those factors.
> >>
> >> Changes in V5:
> >> -- delete dsc_id[]
> >> -- update to global_state->dsc_to_enc_id[] directly
> >> -- replace ndx with idx
> >> -- fix indentation at function declaration
> >> -- only one for loop at _dpu_rm_reserve_dsc_single()
> >>
> >> Changes in V4:
> >> -- rework commit message
> >> -- use reserved_by_other()
> >> -- add _dpu_rm_pingpong_next_index()
> >> -- revise _dpu_rm_pingpong_dsc_check()
> >>
> >> Changes in V3:
> >> -- add dpu_rm_pingpong_dsc_check()
> >> -- for pair allocation use i += 2 at for loop
> >>
> >> Changes in V2:
> >>  -- split _dpu_rm_reserve_dsc() into _dpu_rm_reserve_dsc_single() and
> >> _dpu_rm_reserve_dsc_pair()
> >>
> >> Fixes: f2803ee91a41 ("drm/msm/disp/dpu1: Add DSC support in RM")
> >> Signed-off-by: Kuogee Hsieh 
> >> ---
> >>   drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 162 
> >> +
> >>   1 file changed, 146 insertions(+), 16 deletions(-)
> >>
> >> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c 
> >> b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
> >> index f9215643..7c7a88f 100644
> >> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
> >> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
> >> @@ -461,29 +461,159 @@ static int _dpu_rm_reserve_ctls(
> >>  return 0;
> >>   }
> >>
> >> -static int _dpu_rm_reserve_dsc(struct dpu_rm *rm,
> >> -  struct dpu_global_state *global_state,
> >> -  struct drm_encoder *enc,
> >> -  const struct msm_display_topology *top)
> >> +static int _dpu_rm_pingpong_next_index(int start,
> >> +  uint32_t enc_id,
> >> +  uint32_t *pp_to_enc_id,
> >> +  int pp_max)
> >>   {
> >> -   int num_dsc = top->num_dsc;
> >>  int i;
> >>
> >> -   /* check if DSC required are allocated or not */
> >> -   for (i = 0; i < num_dsc; i++) {
> >> -   if (!rm->dsc_blks[i]) {
> >> -   DPU_ERROR("DSC %d does not exist\n", i);
> >> -   return -EIO;
> >> -   }
> >> +   for (i = start; i < pp_max; i++) {
> >> +   if (pp_to_enc_id[i] == enc_id)
> >> +   return i;
> >> +   }
> >> +
> >> +   return -ENAVAIL;
> >> +}
> >> +
> >> +static int _dpu_rm_pingpong_dsc_check(int dsc_idx, int pp_idx)
> >> +{
> >> +
> > CHECK: Blank lines aren't necessary after an open brace '{'
> > #85: FILE: drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:481:
> >
> >> +   /*
> >> +* DSC with even index must be used with the PINGPONG with even 
> >> index
> >> +* DSC with odd index must be used with the PINGPONG with odd index
> >> +*/
> >> +   if ((dsc_idx & 0x01) != (pp_idx & 0x01))
> >> +   return -ENAVAIL;
> >> +
> >> +   return 0;
> >> +}
> >> +
> >> +static int _dpu_rm_reserve_dsc_single(struct dpu_rm *rm,
> >> + struct dpu_global_state 
> >> *global_state,
> >> + uint32_t enc_id,
> >> + const struct msm_display_topology 
> >> *top)
> >> +{
> >> +   int num_dsc = 0;
> >> +   uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id;
> >> +   uint32_t *dsc_enc_id = global_state->dsc_to_enc_id;
> >> +   int pp_max = PINGPONG_MAX - PINGPONG_0;
> >> +   int pp_idx;
> >> +   int dsc_idx;
> >> +   int ret;
> >> +
> >> +   for (dsc_idx = 0; dsc_idx < ARRAY_SIZE(rm->dsc_blks) &&
> >> + num_dsc < 1; dsc_idx++) {
> > The condition is wrong here. Also it is misaligned.
>
> i will remove checking  num_dsc < 1 here and add break at end of body of
> for loop since it only allocate one dsc

I thought we established that in v4 or v3 that _single can get two DSC
interfaces to be allocated.

   if (top->num_dsc > top->num_intf)   /* merge mode */
   return _dpu_rm_reserve_dsc_pair(rm, global_state, enc_id, top);
   

Re: [PATCH v5] drm/msm/dpu: improve DSC allocation

2023-12-14 Thread Kuogee Hsieh



On 12/13/2023 3:00 PM, Dmitry Baryshkov wrote:

On Wed, 13 Dec 2023 at 20:58, Kuogee Hsieh  wrote:

At DSC V1.1 DCE (Display Compression Engine) contains a DSC encoder.
However, at DSC V1.2 DCE consists of two DSC encoders, one has an odd
index and another one has an even index. Each encoder can work
independently. But only two DSC encoders from same DCE can be paired
to work together to support DSC merge mode at DSC V1.2. For DSC V1.1
two consecutive DSC encoders (start with even index) have to be paired
to support DSC merge mode.  In addition, the DSC with even index have
to be mapped to even PINGPONG index and DSC with odd index have to be
mapped to odd PINGPONG index at its data path in regardless of DSC
V1.1 or V1.2. This patch improves DSC allocation mechanism with
consideration of those factors.

Changes in V5:
-- delete dsc_id[]
-- update to global_state->dsc_to_enc_id[] directly
-- replace ndx with idx
-- fix indentation at function declaration
-- only one for loop at _dpu_rm_reserve_dsc_single()

Changes in V4:
-- rework commit message
-- use reserved_by_other()
-- add _dpu_rm_pingpong_next_index()
-- revise _dpu_rm_pingpong_dsc_check()

Changes in V3:
-- add dpu_rm_pingpong_dsc_check()
-- for pair allocation use i += 2 at for loop

Changes in V2:
 -- split _dpu_rm_reserve_dsc() into _dpu_rm_reserve_dsc_single() and
_dpu_rm_reserve_dsc_pair()

Fixes: f2803ee91a41 ("drm/msm/disp/dpu1: Add DSC support in RM")
Signed-off-by: Kuogee Hsieh 
---
  drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 162 +
  1 file changed, 146 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
index f9215643..7c7a88f 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
@@ -461,29 +461,159 @@ static int _dpu_rm_reserve_ctls(
 return 0;
  }

-static int _dpu_rm_reserve_dsc(struct dpu_rm *rm,
-  struct dpu_global_state *global_state,
-  struct drm_encoder *enc,
-  const struct msm_display_topology *top)
+static int _dpu_rm_pingpong_next_index(int start,
+  uint32_t enc_id,
+  uint32_t *pp_to_enc_id,
+  int pp_max)
  {
-   int num_dsc = top->num_dsc;
 int i;

-   /* check if DSC required are allocated or not */
-   for (i = 0; i < num_dsc; i++) {
-   if (!rm->dsc_blks[i]) {
-   DPU_ERROR("DSC %d does not exist\n", i);
-   return -EIO;
-   }
+   for (i = start; i < pp_max; i++) {
+   if (pp_to_enc_id[i] == enc_id)
+   return i;
+   }
+
+   return -ENAVAIL;
+}
+
+static int _dpu_rm_pingpong_dsc_check(int dsc_idx, int pp_idx)
+{
+

CHECK: Blank lines aren't necessary after an open brace '{'
#85: FILE: drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:481:


+   /*
+* DSC with even index must be used with the PINGPONG with even index
+* DSC with odd index must be used with the PINGPONG with odd index
+*/
+   if ((dsc_idx & 0x01) != (pp_idx & 0x01))
+   return -ENAVAIL;
+
+   return 0;
+}
+
+static int _dpu_rm_reserve_dsc_single(struct dpu_rm *rm,
+ struct dpu_global_state *global_state,
+ uint32_t enc_id,
+ const struct msm_display_topology *top)
+{
+   int num_dsc = 0;
+   uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id;
+   uint32_t *dsc_enc_id = global_state->dsc_to_enc_id;
+   int pp_max = PINGPONG_MAX - PINGPONG_0;
+   int pp_idx;
+   int dsc_idx;
+   int ret;
+
+   for (dsc_idx = 0; dsc_idx < ARRAY_SIZE(rm->dsc_blks) &&
+ num_dsc < 1; dsc_idx++) {

The condition is wrong here. Also it is misaligned.


i will remove checking  num_dsc < 1 here and add break at end of body of 
for loop since it only allocate one dsc






+   if (!rm->dsc_blks[dsc_idx])
+   continue;
+
+   if (reserved_by_other(dsc_enc_id, dsc_idx, enc_id))
+   continue;
+
+   pp_idx = _dpu_rm_pingpong_next_index(0, enc_id,

And this is wrong too. You should start relatively to your previous PP index.


It does not have previous pp_index since it only allocate on dsc.




+pp_to_enc_id, pp_max);
+   if (pp_idx < 0)
+   return -ENAVAIL;
+
+   ret = _dpu_rm_pingpong_dsc_check(dsc_idx, pp_idx);
+   if (ret)
+   return -ENAVAIL;
+
+   dsc_enc_id[dsc_idx] = enc_id;
+   num_dsc++;
+   }
+
+   if (!num_dsc) {
+   DPU_ERROR("DSC allocation 

Re: [PATCH v5] drm/msm/dpu: improve DSC allocation

2023-12-14 Thread Kuogee Hsieh



On 12/13/2023 3:00 PM, Dmitry Baryshkov wrote:

On Wed, 13 Dec 2023 at 20:58, Kuogee Hsieh  wrote:

At DSC V1.1 DCE (Display Compression Engine) contains a DSC encoder.
However, at DSC V1.2 DCE consists of two DSC encoders, one has an odd
index and another one has an even index. Each encoder can work
independently. But only two DSC encoders from same DCE can be paired
to work together to support DSC merge mode at DSC V1.2. For DSC V1.1
two consecutive DSC encoders (start with even index) have to be paired
to support DSC merge mode.  In addition, the DSC with even index have
to be mapped to even PINGPONG index and DSC with odd index have to be
mapped to odd PINGPONG index at its data path in regardless of DSC
V1.1 or V1.2. This patch improves DSC allocation mechanism with
consideration of those factors.

Changes in V5:
-- delete dsc_id[]
-- update to global_state->dsc_to_enc_id[] directly
-- replace ndx with idx
-- fix indentation at function declaration
-- only one for loop at _dpu_rm_reserve_dsc_single()

Changes in V4:
-- rework commit message
-- use reserved_by_other()
-- add _dpu_rm_pingpong_next_index()
-- revise _dpu_rm_pingpong_dsc_check()

Changes in V3:
-- add dpu_rm_pingpong_dsc_check()
-- for pair allocation use i += 2 at for loop

Changes in V2:
 -- split _dpu_rm_reserve_dsc() into _dpu_rm_reserve_dsc_single() and
_dpu_rm_reserve_dsc_pair()

Fixes: f2803ee91a41 ("drm/msm/disp/dpu1: Add DSC support in RM")
Signed-off-by: Kuogee Hsieh 
---
  drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 162 +
  1 file changed, 146 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
index f9215643..7c7a88f 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
@@ -461,29 +461,159 @@ static int _dpu_rm_reserve_ctls(
 return 0;
  }

-static int _dpu_rm_reserve_dsc(struct dpu_rm *rm,
-  struct dpu_global_state *global_state,
-  struct drm_encoder *enc,
-  const struct msm_display_topology *top)
+static int _dpu_rm_pingpong_next_index(int start,
+  uint32_t enc_id,
+  uint32_t *pp_to_enc_id,
+  int pp_max)
  {
-   int num_dsc = top->num_dsc;
 int i;

-   /* check if DSC required are allocated or not */
-   for (i = 0; i < num_dsc; i++) {
-   if (!rm->dsc_blks[i]) {
-   DPU_ERROR("DSC %d does not exist\n", i);
-   return -EIO;
-   }
+   for (i = start; i < pp_max; i++) {
+   if (pp_to_enc_id[i] == enc_id)
+   return i;
+   }
+
+   return -ENAVAIL;
+}
+
+static int _dpu_rm_pingpong_dsc_check(int dsc_idx, int pp_idx)
+{
+

CHECK: Blank lines aren't necessary after an open brace '{'
#85: FILE: drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:481:


+   /*
+* DSC with even index must be used with the PINGPONG with even index
+* DSC with odd index must be used with the PINGPONG with odd index
+*/
+   if ((dsc_idx & 0x01) != (pp_idx & 0x01))
+   return -ENAVAIL;
+
+   return 0;
+}
+
+static int _dpu_rm_reserve_dsc_single(struct dpu_rm *rm,
+ struct dpu_global_state *global_state,
+ uint32_t enc_id,
+ const struct msm_display_topology *top)
+{
+   int num_dsc = 0;
+   uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id;
+   uint32_t *dsc_enc_id = global_state->dsc_to_enc_id;
+   int pp_max = PINGPONG_MAX - PINGPONG_0;
+   int pp_idx;
+   int dsc_idx;
+   int ret;
+
+   for (dsc_idx = 0; dsc_idx < ARRAY_SIZE(rm->dsc_blks) &&
+ num_dsc < 1; dsc_idx++) {

The condition is wrong here. Also it is misaligned.


+   if (!rm->dsc_blks[dsc_idx])
+   continue;
+
+   if (reserved_by_other(dsc_enc_id, dsc_idx, enc_id))
+   continue;
+
+   pp_idx = _dpu_rm_pingpong_next_index(0, enc_id,

And this is wrong too. You should start relatively to your previous PP index.


+pp_to_enc_id, pp_max);
+   if (pp_idx < 0)
+   return -ENAVAIL;
+
+   ret = _dpu_rm_pingpong_dsc_check(dsc_idx, pp_idx);
+   if (ret)
+   return -ENAVAIL;
+
+   dsc_enc_id[dsc_idx] = enc_id;
+   num_dsc++;
+   }
+
+   if (!num_dsc) {
+   DPU_ERROR("DSC allocation failed num_dsc=%d\n", num_dsc);
+   return -ENAVAIL;
+   }

-   if (global_state->dsc_to_enc_id[i]) {
-   DPU_ERROR("DSC %d is already 

Re: [PATCH v5] drm/msm/dpu: improve DSC allocation

2023-12-13 Thread Dmitry Baryshkov
On Wed, 13 Dec 2023 at 20:58, Kuogee Hsieh  wrote:
>
> At DSC V1.1 DCE (Display Compression Engine) contains a DSC encoder.
> However, at DSC V1.2 DCE consists of two DSC encoders, one has an odd
> index and another one has an even index. Each encoder can work
> independently. But only two DSC encoders from same DCE can be paired
> to work together to support DSC merge mode at DSC V1.2. For DSC V1.1
> two consecutive DSC encoders (start with even index) have to be paired
> to support DSC merge mode.  In addition, the DSC with even index have
> to be mapped to even PINGPONG index and DSC with odd index have to be
> mapped to odd PINGPONG index at its data path in regardless of DSC
> V1.1 or V1.2. This patch improves DSC allocation mechanism with
> consideration of those factors.
>
> Changes in V5:
> -- delete dsc_id[]
> -- update to global_state->dsc_to_enc_id[] directly
> -- replace ndx with idx
> -- fix indentation at function declaration
> -- only one for loop at _dpu_rm_reserve_dsc_single()
>
> Changes in V4:
> -- rework commit message
> -- use reserved_by_other()
> -- add _dpu_rm_pingpong_next_index()
> -- revise _dpu_rm_pingpong_dsc_check()
>
> Changes in V3:
> -- add dpu_rm_pingpong_dsc_check()
> -- for pair allocation use i += 2 at for loop
>
> Changes in V2:
> -- split _dpu_rm_reserve_dsc() into _dpu_rm_reserve_dsc_single() and
>_dpu_rm_reserve_dsc_pair()
>
> Fixes: f2803ee91a41 ("drm/msm/disp/dpu1: Add DSC support in RM")
> Signed-off-by: Kuogee Hsieh 
> ---
>  drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 162 
> +
>  1 file changed, 146 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c 
> b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
> index f9215643..7c7a88f 100644
> --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
> +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
> @@ -461,29 +461,159 @@ static int _dpu_rm_reserve_ctls(
> return 0;
>  }
>
> -static int _dpu_rm_reserve_dsc(struct dpu_rm *rm,
> -  struct dpu_global_state *global_state,
> -  struct drm_encoder *enc,
> -  const struct msm_display_topology *top)
> +static int _dpu_rm_pingpong_next_index(int start,
> +  uint32_t enc_id,
> +  uint32_t *pp_to_enc_id,
> +  int pp_max)
>  {
> -   int num_dsc = top->num_dsc;
> int i;
>
> -   /* check if DSC required are allocated or not */
> -   for (i = 0; i < num_dsc; i++) {
> -   if (!rm->dsc_blks[i]) {
> -   DPU_ERROR("DSC %d does not exist\n", i);
> -   return -EIO;
> -   }
> +   for (i = start; i < pp_max; i++) {
> +   if (pp_to_enc_id[i] == enc_id)
> +   return i;
> +   }
> +
> +   return -ENAVAIL;
> +}
> +
> +static int _dpu_rm_pingpong_dsc_check(int dsc_idx, int pp_idx)
> +{
> +

CHECK: Blank lines aren't necessary after an open brace '{'
#85: FILE: drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c:481:

> +   /*
> +* DSC with even index must be used with the PINGPONG with even index
> +* DSC with odd index must be used with the PINGPONG with odd index
> +*/
> +   if ((dsc_idx & 0x01) != (pp_idx & 0x01))
> +   return -ENAVAIL;
> +
> +   return 0;
> +}
> +
> +static int _dpu_rm_reserve_dsc_single(struct dpu_rm *rm,
> + struct dpu_global_state *global_state,
> + uint32_t enc_id,
> + const struct msm_display_topology *top)
> +{
> +   int num_dsc = 0;
> +   uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id;
> +   uint32_t *dsc_enc_id = global_state->dsc_to_enc_id;
> +   int pp_max = PINGPONG_MAX - PINGPONG_0;
> +   int pp_idx;
> +   int dsc_idx;
> +   int ret;
> +
> +   for (dsc_idx = 0; dsc_idx < ARRAY_SIZE(rm->dsc_blks) &&
> + num_dsc < 1; dsc_idx++) {

The condition is wrong here. Also it is misaligned.

> +   if (!rm->dsc_blks[dsc_idx])
> +   continue;
> +
> +   if (reserved_by_other(dsc_enc_id, dsc_idx, enc_id))
> +   continue;
> +
> +   pp_idx = _dpu_rm_pingpong_next_index(0, enc_id,

And this is wrong too. You should start relatively to your previous PP index.

> +pp_to_enc_id, pp_max);
> +   if (pp_idx < 0)
> +   return -ENAVAIL;
> +
> +   ret = _dpu_rm_pingpong_dsc_check(dsc_idx, pp_idx);
> +   if (ret)
> +   return -ENAVAIL;
> +
> +   dsc_enc_id[dsc_idx] = enc_id;
> +   num_dsc++;
> +   }
> +
> +   if (!num_dsc) {
> +   DPU_ERROR("DSC allocation failed 

[PATCH v5] drm/msm/dpu: improve DSC allocation

2023-12-13 Thread Kuogee Hsieh
At DSC V1.1 DCE (Display Compression Engine) contains a DSC encoder.
However, at DSC V1.2 DCE consists of two DSC encoders, one has an odd
index and another one has an even index. Each encoder can work
independently. But only two DSC encoders from same DCE can be paired
to work together to support DSC merge mode at DSC V1.2. For DSC V1.1
two consecutive DSC encoders (start with even index) have to be paired
to support DSC merge mode.  In addition, the DSC with even index have
to be mapped to even PINGPONG index and DSC with odd index have to be
mapped to odd PINGPONG index at its data path in regardless of DSC
V1.1 or V1.2. This patch improves DSC allocation mechanism with
consideration of those factors.

Changes in V5:
-- delete dsc_id[]
-- update to global_state->dsc_to_enc_id[] directly
-- replace ndx with idx
-- fix indentation at function declaration
-- only one for loop at _dpu_rm_reserve_dsc_single()

Changes in V4:
-- rework commit message
-- use reserved_by_other()
-- add _dpu_rm_pingpong_next_index()
-- revise _dpu_rm_pingpong_dsc_check()

Changes in V3:
-- add dpu_rm_pingpong_dsc_check()
-- for pair allocation use i += 2 at for loop

Changes in V2:
-- split _dpu_rm_reserve_dsc() into _dpu_rm_reserve_dsc_single() and
   _dpu_rm_reserve_dsc_pair()

Fixes: f2803ee91a41 ("drm/msm/disp/dpu1: Add DSC support in RM")
Signed-off-by: Kuogee Hsieh 
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c | 162 +
 1 file changed, 146 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c 
b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
index f9215643..7c7a88f 100644
--- a/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
+++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_rm.c
@@ -461,29 +461,159 @@ static int _dpu_rm_reserve_ctls(
return 0;
 }
 
-static int _dpu_rm_reserve_dsc(struct dpu_rm *rm,
-  struct dpu_global_state *global_state,
-  struct drm_encoder *enc,
-  const struct msm_display_topology *top)
+static int _dpu_rm_pingpong_next_index(int start,
+  uint32_t enc_id,
+  uint32_t *pp_to_enc_id,
+  int pp_max)
 {
-   int num_dsc = top->num_dsc;
int i;
 
-   /* check if DSC required are allocated or not */
-   for (i = 0; i < num_dsc; i++) {
-   if (!rm->dsc_blks[i]) {
-   DPU_ERROR("DSC %d does not exist\n", i);
-   return -EIO;
-   }
+   for (i = start; i < pp_max; i++) {
+   if (pp_to_enc_id[i] == enc_id)
+   return i;
+   }
+
+   return -ENAVAIL;
+}
+
+static int _dpu_rm_pingpong_dsc_check(int dsc_idx, int pp_idx)
+{
+
+   /*
+* DSC with even index must be used with the PINGPONG with even index
+* DSC with odd index must be used with the PINGPONG with odd index
+*/
+   if ((dsc_idx & 0x01) != (pp_idx & 0x01))
+   return -ENAVAIL;
+
+   return 0;
+}
+
+static int _dpu_rm_reserve_dsc_single(struct dpu_rm *rm,
+ struct dpu_global_state *global_state,
+ uint32_t enc_id,
+ const struct msm_display_topology *top)
+{
+   int num_dsc = 0;
+   uint32_t *pp_to_enc_id = global_state->pingpong_to_enc_id;
+   uint32_t *dsc_enc_id = global_state->dsc_to_enc_id;
+   int pp_max = PINGPONG_MAX - PINGPONG_0;
+   int pp_idx;
+   int dsc_idx;
+   int ret;
+
+   for (dsc_idx = 0; dsc_idx < ARRAY_SIZE(rm->dsc_blks) &&
+ num_dsc < 1; dsc_idx++) {
+   if (!rm->dsc_blks[dsc_idx])
+   continue;
+
+   if (reserved_by_other(dsc_enc_id, dsc_idx, enc_id))
+   continue;
+
+   pp_idx = _dpu_rm_pingpong_next_index(0, enc_id,
+pp_to_enc_id, pp_max);
+   if (pp_idx < 0)
+   return -ENAVAIL;
+
+   ret = _dpu_rm_pingpong_dsc_check(dsc_idx, pp_idx);
+   if (ret)
+   return -ENAVAIL;
+
+   dsc_enc_id[dsc_idx] = enc_id;
+   num_dsc++;
+   }
+
+   if (!num_dsc) {
+   DPU_ERROR("DSC allocation failed num_dsc=%d\n", num_dsc);
+   return -ENAVAIL;
+   }
 
-   if (global_state->dsc_to_enc_id[i]) {
-   DPU_ERROR("DSC %d is already allocated\n", i);
-   return -EIO;
+   return 0;
+}
+
+static int _dpu_rm_reserve_dsc_pair(struct dpu_rm *rm,
+   struct dpu_global_state *global_state,
+   uint32_t enc_id,
+   const struct msm_display_topology *top)
+{
+   int num_dsc = 0;
+