From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUlN9-00063N-Fk for qemu-devel@nongnu.org; Thu, 18 Sep 2014 19:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XUlMz-0003Jo-89 for qemu-devel@nongnu.org; Thu, 18 Sep 2014 19:44:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64764) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XUlMz-0003JL-03 for qemu-devel@nongnu.org; Thu, 18 Sep 2014 19:44:13 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8INi7J6014468 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Thu, 18 Sep 2014 19:44:07 -0400 From: John Snow Date: Thu, 18 Sep 2014 19:43:26 -0400 Message-Id: <1411083819-9284-3-git-send-email-jsnow@redhat.com> In-Reply-To: <1411083819-9284-1-git-send-email-jsnow@redhat.com> References: <1411083819-9284-1-git-send-email-jsnow@redhat.com> Subject: [Qemu-devel] [PATCH 02/15] qtest/ahci: Add port_select helper List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, mst@redhat.com, armbru@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, John Snow This helper identifies which port of the AHCI HBA has a device we may run tests on. Signed-off-by: John Snow --- 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