[v3,09/11] astbmc: Use LPC probe calls to determine SIO presence

Message ID 20181009073237.16251-10-andrew@aj.id.au
State Accepted
Headers show
Series
  • Add and integrate an IPMI flash implementation
Related show

Checks

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

Commit Message

Andrew Jeffery Oct. 9, 2018, 7:32 a.m.
Avoid the probabilistic approach and use a deterministic one instead.
The probe calls use a slow, synchronous method to capture the the state
of the target device, so it is used sparingly (only on first access).

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

Patch

diff --git a/hw/ast-bmc/ast-io.c b/hw/ast-bmc/ast-io.c
index 7f8c2dafa5ef..e05348487fd4 100644
--- a/hw/ast-bmc/ast-io.c
+++ b/hw/ast-bmc/ast-io.c
@@ -323,36 +323,26 @@  static void ast_setup_sio_irq_polarity(void)
 
 static bool ast_sio_is_enabled(void)
 {
-	bool enabled;
+	int64_t rc;
 
-	lpc_outb(0xa5, 0x2e);
-	lpc_outb(0xa5, 0x2e);
+	/* Begin the unlock sequence with a probe to establish presence */
+	rc = lpc_probe_write(OPAL_LPC_IO, 0x2e, 0xa5, 1);
+	if (rc)
+		return false;
 
-	/* Heuristic attempt to confirm SIO is enabled.
-	 *
-	 * Do two tests of 1 byte, giving a false positive probability of
-	 * 1/65536. Read tests on disabled SIO tended to return 0x60.
-	 */
-	bmc_sio_outb(0x2, 0x07);
-	enabled = bmc_sio_inb(0x07) == 2;
-	if (enabled) {
-		bmc_sio_outb(0xd, 0x07);
-		enabled = bmc_sio_inb(0x07) == 0xd;
-	}
+	/* Complete the unlock sequence if the device is present */
+	lpc_outb(0xa5, 0x2e);
 
-	if (enabled)
-		lpc_outb(0xaa, 0x2e);
+	/* Re-lock to return to a known state */
+	lpc_outb(0xaa, 0x2e);
 
-	return enabled;
+	return true;
 }
 
 bool ast_sio_init(void)
 {
 	bool enabled = ast_sio_is_enabled();
 
-	prlog(PR_NOTICE, "PLAT: SuperIO is %s\n",
-	      enabled ? "available" : "unavailable!");
-
 	/* Configure all AIO interrupts to level low */
 	if (enabled)
 		ast_setup_sio_irq_polarity();