diff mbox series

[v2,1/5] phb4: Rework BDFN filtering in phb4_set_pe()

Message ID 20190131071545.31869-1-oohall@gmail.com
State Superseded
Headers show
Series [v2,1/5] phb4: Rework BDFN filtering in phb4_set_pe() | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot success Test snowpatch/job/snowpatch-skiboot on branch master

Commit Message

Oliver O'Halloran Jan. 31, 2019, 7:15 a.m. UTC
General cleanup. For a function that does nothing more than a
mask-and-compare the current implementation is way more convoluted
than it has any right to be.

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 hw/phb4.c | 58 ++++++++++++++++---------------------------------------
 1 file changed, 17 insertions(+), 41 deletions(-)
diff mbox series

Patch

diff --git a/hw/phb4.c b/hw/phb4.c
index 5163f82f6e68..50496d51d38e 100644
--- a/hw/phb4.c
+++ b/hw/phb4.c
@@ -2109,8 +2109,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, idx;
 	uint16_t *rte;
 
 	/* Sanity check */
@@ -2124,55 +2123,32 @@  static int64_t phb4_set_pe(struct phb *phb,
 	    fcompare > OPAL_COMPARE_RID_FUNCTION_NUMBER)
 		return OPAL_PARAMETER;
 
+	/* match everything by default */
+	mask = 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);
 
-	if (dcompare == OPAL_IGNORE_RID_DEVICE_NUMBER)
-		all = (all << 1) | 0x1;
-	else {
+	if (dcompare == OPAL_COMPARE_RID_DEVICE_NUMBER)
 		mask |= 0xf8;
-		val  |= (bdfn & 0xf8);
-	}
 
-	if (fcompare == OPAL_IGNORE_RID_FUNCTION_NUMBER)
-		all = (all << 1) | 0x1;
-	else {
+	if (fcompare == OPAL_COMPARE_RID_FUNCTION_NUMBER)
 		mask |= 0x7;
-		val  |= (bdfn & 0x7);
-	}
+
+	if (action == OPAL_UNMAP_PE)
+		pe_number = PHB4_RESERVED_PE_NUM(p);
 
 	/* 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++) {
+		if ((idx & mask) == (bdfn & mask)) {
+			p->rte_cache[idx] = pe_number;
+			rte[idx] = pe_number;
 		}
 	}
 
-	/* Invalidate the entire RTC */
+	/* Invalidate the RID Translation Cache (RTC) inside the PHB */
 	out_be64(p->regs + PHB_RTC_INVALIDATE, PHB_RTC_INVALIDATE_ALL);
 
 	return OPAL_SUCCESS;