The available PE#, represented by a bitmap in the PHB, is allocated
in asending order. It conflicts with the fact that M64 segments are
assigned in same order. In order to avoid the conflict, the patch
allocates PE# in deasending order.

Signed-off-by: Gavin Shan <[email protected]>
---
v5:
  * Split from [PATCH v5 v4 06/21]
---
 arch/powerpc/platforms/powernv/pci-ioda.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c 
b/arch/powerpc/platforms/powernv/pci-ioda.c
index d8b0ef5..0d6539a 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -152,18 +152,23 @@ static void pnv_ioda_reserve_pe(struct pnv_phb *phb, int 
pe_no)
 
 static int pnv_ioda_alloc_pe(struct pnv_phb *phb)
 {
-       unsigned long pe;
+       unsigned long pe_no;
+       unsigned long limit = phb->ioda.total_pe - 1;
 
        do {
-               pe = find_next_zero_bit(phb->ioda.pe_alloc,
-                                       phb->ioda.total_pe, 0);
-               if (pe >= phb->ioda.total_pe)
+               pe_no = find_next_zero_bit(phb->ioda.pe_alloc,
+                                          phb->ioda.total_pe, limit);
+               if (pe_no < phb->ioda.total_pe &&
+                   !test_and_set_bit(pe_no, phb->ioda.pe_alloc))
+                       break;
+
+               if (--limit >= phb->ioda.total_pe)
                        return IODA_INVALID_PE;
-       } while(test_and_set_bit(pe, phb->ioda.pe_alloc));
+       } while (1);
 
-       phb->ioda.pe_array[pe].phb = phb;
-       phb->ioda.pe_array[pe].pe_number = pe;
-       return pe;
+       phb->ioda.pe_array[pe_no].phb = phb;
+       phb->ioda.pe_array[pe_no].pe_number = pe_no;
+       return pe_no;
 }
 
 static void pnv_ioda_free_pe(struct pnv_phb *phb, int pe)
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to