[RFC,1/4] phb4: Rework bdfn filtering in set_pe

Message ID 20180912095248.27557-2-oohall@gmail.com
State New
Headers show
Series
  • [RFC,1/4] phb4: Rework bdfn filtering in set_pe
Related show

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied

Commit Message

Oliver Sept. 12, 2018, 9:52 a.m.
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hw/phb4.c | 56 ++++++++++++++++++++------------------------------------
 1 file changed, 20 insertions(+), 36 deletions(-)

Patch

diff --git a/hw/phb4.c b/hw/phb4.c
index d1245dce5adf..f0cbb4852558 100644
--- a/hw/phb4.c
+++ b/hw/phb4.c
@@ -2159,8 +2159,7 @@  static int64_t phb4_set_pe(struct phb *phb,
 			   uint8_t action)
 {
 	struct phb4 *p = phb_to_phb4(phb);
-	uint64_t mask, val, tmp, idx;
-	int32_t all = 0;
+	uint64_t mask, val, idx;
 	uint16_t *rte;
 
 	/* Sanity check */
@@ -2174,52 +2173,37 @@  static int64_t phb4_set_pe(struct phb *phb,
 	    fcompare > OPAL_COMPARE_RID_FUNCTION_NUMBER)
 		return OPAL_PARAMETER;
 
+	/* match everything by default */
+	mask = 0;
+	val = 0;
+
 	/* Figure out the RID range */
-	if (bcompare == OpalPciBusAny) {
-		mask = 0x0;
-		val  = 0x0;
-		all  = 0x1;
-	} else {
-		tmp  = ((0x1 << (bcompare + 1)) - 1) << (15 - bcompare);
-		mask = tmp;
-		val  = bdfn & tmp;
+	if (bcompare != OpalPciBusAny) {
+		mask  = ((0x1 << (bcompare + 1)) - 1) << (15 - bcompare);
+		val   = bdfn & mask;
 	}
 
-	if (dcompare == OPAL_IGNORE_RID_DEVICE_NUMBER)
-		all = (all << 1) | 0x1;
-	else {
+	if (dcompare != OPAL_IGNORE_RID_DEVICE_NUMBER) {
 		mask |= 0xf8;
 		val  |= (bdfn & 0xf8);
 	}
 
-	if (fcompare == OPAL_IGNORE_RID_FUNCTION_NUMBER)
-		all = (all << 1) | 0x1;
-	else {
+	if (fcompare != OPAL_IGNORE_RID_FUNCTION_NUMBER) {
 		mask |= 0x7;
 		val  |= (bdfn & 0x7);
 	}
 
 	/* Map or unmap the RTT range */
-	if (all == 0x7) {
-		if (action == OPAL_MAP_PE) {
-			for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++)
-				p->rte_cache[idx] = pe_number;
-		} else {
-			for (idx = 0; idx < ARRAY_SIZE(p->rte_cache); idx++)
-				p->rte_cache[idx] = PHB4_RESERVED_PE_NUM(p);
-		}
-		memcpy((void *)p->tbl_rtt, p->rte_cache, RTT_TABLE_SIZE);
-	} else {
-		rte = (uint16_t *)p->tbl_rtt;
-		for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++, rte++) {
-			if ((idx & mask) != val)
-				continue;
-			if (action == OPAL_MAP_PE)
-				p->rte_cache[idx] = pe_number;
-			else
-				p->rte_cache[idx] = PHB4_RESERVED_PE_NUM(p);
-			*rte = p->rte_cache[idx];
-		}
+	rte = (uint16_t *)p->tbl_rtt;
+	for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++, rte++) {
+		if ((idx & mask) != val)
+			continue;
+
+		if (action == OPAL_MAP_PE)
+			p->rte_cache[idx] = pe_number;
+		else
+			p->rte_cache[idx] = PHB4_RESERVED_PE_NUM(p);
+		*rte = p->rte_cache[idx];
 	}
 
 	/* Invalidate the entire RTC */