[Skiboot] [PATCH 1/2] ast-io: Rework ast_sio_is_enabled() test sequence

Andrew Jeffery andrew at aj.id.au
Thu Feb 21 15:50:22 AEDT 2019


The postcondition of probing with a lock sequence is easier to make
correct than with unlock. The original implementation left SuperIO
locked after execution which broke an assumption of some callers.

Tested on Garrison, Palmetto without HIOMAP, Palmetto with HIOMAP and
Witherspoon.

Signed-off-by: Andrew Jeffery <andrew at aj.id.au>
---
 hw/ast-bmc/ast-io.c | 39 ++++++++++++++++++++++++++++++---------
 1 file changed, 30 insertions(+), 9 deletions(-)

diff --git a/hw/ast-bmc/ast-io.c b/hw/ast-bmc/ast-io.c
index 38ca86c46003..a9da06b24057 100644
--- a/hw/ast-bmc/ast-io.c
+++ b/hw/ast-bmc/ast-io.c
@@ -323,20 +323,41 @@ static void ast_setup_sio_irq_polarity(void)
 
 bool ast_sio_is_enabled(void)
 {
+	bool enabled;
 	int64_t rc;
 
-	/* Begin the unlock sequence with a probe to establish presence */
-	rc = lpc_probe_write(OPAL_LPC_IO, 0x2e, 0xa5, 1);
-	if (rc)
-		return false;
+	lock(&bmc_sio_lock);
+	/*
+	 * Probe by attempting to lock the SIO device, this way the
+	 * post-condition is that the SIO device is locked or not able to be
+	 * unlocked. This turns out neater than trying to use the unlock code.
+	 */
+	rc = lpc_probe_write(OPAL_LPC_IO, 0x2e, 0xaa, 1);
+	if (rc) {
+		enabled = false;
+		/* If we can't lock it, then we can't unlock it either */
+		goto out;
+	}
 
-	/* Complete the unlock sequence if the device is present */
-	lpc_outb(0xa5, 0x2e);
+	/*
+	 * Now that we know that is locked and able to be unlocked, unlock it
+	 * if skiboot's recorded device state indicates it was previously
+	 * unlocked.
+	 */
+	if (bmc_sio_cur_dev != BMC_SIO_DEV_NONE) {
+		/* Send SuperIO password */
+		lpc_outb(0xa5, 0x2e);
+		lpc_outb(0xa5, 0x2e);
 
-	/* Re-lock to return to a known state */
-	lpc_outb(0xaa, 0x2e);
+		/* Ensure the previously selected logical dev is selected */
+		bmc_sio_outb(bmc_sio_cur_dev, 0x07);
+	}
 
-	return true;
+	enabled = true;
+out:
+	unlock(&bmc_sio_lock);
+
+	return enabled;
 }
 
 bool ast_sio_init(void)
-- 
2.19.1



More information about the Skiboot mailing list