qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 02/15] qtest/ahci: Add port_select helper


From: John Snow
Subject: [Qemu-devel] [PATCH 02/15] qtest/ahci: Add port_select helper
Date: Thu, 18 Sep 2014 19:43:26 -0400

This helper identifies which port of the AHCI HBA
has a device we may run tests on.

Signed-off-by: John Snow <address@hidden>
---
 tests/ahci-test.c | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/tests/ahci-test.c b/tests/ahci-test.c
index d845635..5739063 100644
--- a/tests/ahci-test.c
+++ b/tests/ahci-test.c
@@ -1235,6 +1235,33 @@ static void ahci_test_port_spec(AHCIState *ahci, uint8_t 
port)
 }
 
 /**
+ * Pick the first implemented and running port
+ */
+static unsigned port_select(AHCIState *ahci)
+{
+    uint32_t ports, reg;
+    unsigned i;
+
+    ports = AHCI_RREG(AHCI_PI);
+    for (i = 0; i < 32; ports >>= 1, ++i) {
+        if (ports == 0) {
+            i = 32;
+        }
+
+        if (!(ports & 0x01)) {
+            continue;
+        }
+
+        reg = PX_RREG(i, AHCI_PX_CMD);
+        if (BITSET(reg, AHCI_PX_CMD_ST)) {
+            break;
+        }
+    }
+    g_assert(i < 32);
+    return i;
+}
+
+/**
  * Utilizing an initialized AHCI HBA, issue an IDENTIFY command to the first
  * device we see, then read and check the response.
  */
@@ -1245,7 +1272,7 @@ static void ahci_test_identify(AHCIState *ahci)
     RegH2DFIS fis;
     AHCICommand cmd;
     PRD prd;
-    uint32_t ports, reg, table, data_ptr;
+    uint32_t reg, table, data_ptr;
     uint16_t buff[256];
     unsigned i;
     int rc;
@@ -1267,22 +1294,7 @@ static void ahci_test_identify(AHCIState *ahci)
      */
 
     /* Pick the first implemented and running port */
-    ports = AHCI_RREG(AHCI_PI);
-    for (i = 0; i < 32; ports >>= 1, ++i) {
-        if (ports == 0) {
-            i = 32;
-        }
-
-        if (!(ports & 0x01)) {
-            continue;
-        }
-
-        reg = PX_RREG(i, AHCI_PX_CMD);
-        if (BITSET(reg, AHCI_PX_CMD_ST)) {
-            break;
-        }
-    }
-    g_assert_cmphex(i, <, 32);
+    i = port_select(ahci);
     g_test_message("Selected port %u for test", i);
 
     /* Clear out this port's interrupts (ignore the init register d2h fis) */
-- 
1.9.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]