diff mbox

powerpc/powernv: Fix XSCOM address mangling for form 1 indirect

Message ID 1490319797.28113.46.camel@neuling.org (mailing list archive)
State Accepted
Headers show

Commit Message

Michael Neuling March 24, 2017, 1:43 a.m. UTC
POWER9 adds form 1 scoms. The form of the indirection is specified in
the top nibble of the scom address.

Currently we do some (ugly) bit mangling so that we can fit a 64 bit
scom address into the debugfs interface. The current code only shifts
the top bit (indirect bit).

This patch changes it to shift the whole top nibble so that the form
of the indirection is also shifted.

This patch is backwards compatible with older scoms.

(This change isn't required in the
arch/powerpc/platformspowernv/opal-prd.c scom interface as it passes
the whole 64bit scom address without any bit mangling)

Signed-off-by: Michael Neuling <mikey@neuling.org>
---
(resending to correct linuxppc address)

 arch/powerpc/platforms/powernv/opal-xscom.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

Comments

Michael Ellerman March 31, 2017, 12:33 p.m. UTC | #1
On Fri, 2017-03-24 at 01:43:17 UTC, Michael Neuling wrote:
> POWER9 adds form 1 scoms. The form of the indirection is specified in
> the top nibble of the scom address.
> 
> Currently we do some (ugly) bit mangling so that we can fit a 64 bit
> scom address into the debugfs interface. The current code only shifts
> the top bit (indirect bit).
> 
> This patch changes it to shift the whole top nibble so that the form
> of the indirection is also shifted.
> 
> This patch is backwards compatible with older scoms.
> 
> (This change isn't required in the
> arch/powerpc/platformspowernv/opal-prd.c scom interface as it passes
> the whole 64bit scom address without any bit mangling)
> 
> Signed-off-by: Michael Neuling <mikey@neuling.org>

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/517c27570cf38f182e7a688d50a9b9

cheers
diff mbox

Patch

diff --git a/arch/powerpc/platforms/powernv/opal-xscom.c
b/arch/powerpc/platforms/powernv/opal-xscom.c
index d0ac535cf5..28651fb254 100644
--- a/arch/powerpc/platforms/powernv/opal-xscom.c
+++ b/arch/powerpc/platforms/powernv/opal-xscom.c
@@ -73,25 +73,32 @@  static int opal_xscom_err_xlate(int64_t rc)
 
 static u64 opal_scom_unmangle(u64 addr)
 {
+	u64 tmp;
+
 	/*
-	 * XSCOM indirect addresses have the top bit set. Additionally
-	 * the rest of the top 3 nibbles is always 0.
+	 * XSCOM addresses use the top nibble to set indirect mode and
+	 * its form.  Bits 4-11 are always 0.
 	 *
 	 * Because the debugfs interface uses signed offsets and shifts
 	 * the address left by 3, we basically cannot use the top 4 bits
 	 * of the 64-bit address, and thus cannot use the indirect bit.
 	 *
-	 * To deal with that, we support the indirect bit being in bit
-	 * 4 (IBM notation) instead of bit 0 in this API, we do the
-	 * conversion here. To leave room for further xscom address
-	 * expansion, we only clear out the top byte
+	 * To deal with that, we support the indirect bits being in
+	 * bits 4-7 (IBM notation) instead of bit 0-3 in this API, we
+	 * do the conversion here.
 	 *
-	 * For in-kernel use, we also support the real indirect bit, so
-	 * we test for any of the top 5 bits
+	 * For in-kernel use, we don't need to do this mangling.  In
+	 * kernel won't have bits 4-7 set.
 	 *
+	 * So:
+	 *   debugfs will always   set 0-3 = 0 and clear 4-7
+	 *    kernel will always clear 0-3 = 0 and   set 4-7
 	 */
-	if (addr & (0x1full << 59))
-		addr = (addr & ~(0xffull << 56)) | (1ull << 63);
+	tmp = addr;
+	tmp  &= 0x0f00000000000000;
+	addr &= 0xf0ffffffffffffff;
+	addr |= tmp << 4;
+
 	return addr;
 }