Skip to content

Commit

Permalink
libqos/ahci: Add ahci_port_select helper
Browse files Browse the repository at this point in the history
This helper identifies which port of the
AHCI HBA has a device we may run tests on.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1423158090-25580-2-git-send-email-jsnow@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
jnsnow authored and stefanhaRH committed Feb 16, 2015
1 parent b0e5d90 commit e77448a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
19 changes: 2 additions & 17 deletions tests/ahci-test.c
Expand Up @@ -662,7 +662,7 @@ static void ahci_test_identify(AHCIQState *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;
Expand All @@ -684,22 +684,7 @@ static void ahci_test_identify(AHCIQState *ahci)
*/

/* Pick the first implemented and running port */
ports = ahci_rreg(ahci, AHCI_PI);
for (i = 0; i < 32; ports >>= 1, ++i) {
if (ports == 0) {
i = 32;
}

if (!(ports & 0x01)) {
continue;
}

reg = ahci_px_rreg(ahci, i, AHCI_PX_CMD);
if (BITSET(reg, AHCI_PX_CMD_ST)) {
break;
}
}
g_assert_cmphex(i, <, 32);
i = ahci_port_select(ahci);
g_test_message("Selected port %u for test", i);

/* Clear out this port's interrupts (ignore the init register d2h fis) */
Expand Down
27 changes: 27 additions & 0 deletions tests/libqos/ahci.c
Expand Up @@ -267,3 +267,30 @@ void ahci_hba_enable(AHCIQState *ahci)
* In the future, a small test-case to inspect the Register D2H FIS
* and clear the initial interrupts might be good. */
}

/**
* Pick the first implemented and running port
*/
unsigned ahci_port_select(AHCIQState *ahci)
{
uint32_t ports, reg;
unsigned i;

ports = ahci_rreg(ahci, AHCI_PI);
for (i = 0; i < 32; ports >>= 1, ++i) {
if (ports == 0) {
i = 32;
}

if (!(ports & 0x01)) {
continue;
}

reg = ahci_px_rreg(ahci, i, AHCI_PX_CMD);
if (BITSET(reg, AHCI_PX_CMD_ST)) {
break;
}
}
g_assert(i < 32);
return i;
}
1 change: 1 addition & 0 deletions tests/libqos/ahci.h
Expand Up @@ -431,5 +431,6 @@ void free_ahci_device(QPCIDevice *dev);
void ahci_pci_enable(AHCIQState *ahci);
void start_ahci_device(AHCIQState *ahci);
void ahci_hba_enable(AHCIQState *ahci);
unsigned ahci_port_select(AHCIQState *ahci);

#endif

0 comments on commit e77448a

Please sign in to comment.