From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4DV8-0003QO-R8 for qemu-devel@nongnu.org; Mon, 07 Jul 2014 14:19:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X4DUz-0004IZ-BY for qemu-devel@nongnu.org; Mon, 07 Jul 2014 14:18:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X4DUz-0004IL-3n for qemu-devel@nongnu.org; Mon, 07 Jul 2014 14:18:45 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s67IIhB1019027 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 7 Jul 2014 14:18:44 -0400 From: John Snow Date: Mon, 7 Jul 2014 14:18:06 -0400 Message-Id: <1404757089-4836-26-git-send-email-jsnow@redhat.com> In-Reply-To: <1404757089-4836-1-git-send-email-jsnow@redhat.com> References: <1404757089-4836-1-git-send-email-jsnow@redhat.com> Subject: [Qemu-devel] [PATCH 25/28] ahci: add test_pci_enable to ahci-test. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, John Snow , stefanha@redhat.com, mst@redhat.com This adds a test wherein we engage the PCI AHCI device and ensure that the memory region for the HBA functionality is now accessible. Under Q35 environments, additional PCI configuration is performed to ensure that the HBA functionality will become usable. Signed-off-by: John Snow --- tests/ahci-test.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/tests/ahci-test.c b/tests/ahci-test.c index e0a8f34..7b45064 100644 --- a/tests/ahci-test.c +++ b/tests/ahci-test.c @@ -38,6 +38,13 @@ #include "hw/pci/pci_ids.h" #include "hw/pci/pci_regs.h" +/* Test the Q35/ICH9 behavior in preference to AHCI 1.3 behavior */ +#define Q35 + +#ifndef Q35 +#define AHCI_13_STRICT +#endif + /* Test-specific defines. */ #define TEST_IMAGE_SIZE (64 * 1024 * 1024) @@ -66,6 +73,7 @@ static char tmp_path[] = "/tmp/qtest.XXXXXX"; /*** Function Declarations ***/ static QPCIDevice *get_ahci_device(void); +static QPCIDevice *start_ahci_device(QPCIDevice *dev, HBA **hba_base); static void free_ahci_device(QPCIDevice *dev); static void ahci_test_pci_spec(QPCIDevice *ahci); static void ahci_test_pci_caps(QPCIDevice *ahci, uint16_t header, @@ -174,6 +182,58 @@ static void ahci_shutdown(QPCIDevice *ahci) qtest_shutdown(); } +/*** Logical Device Initialization ***/ + +/** + * Start the PCI device and sanity-check default operation. + */ +static void ahci_pci_enable(QPCIDevice *ahci, HBA **hba_base) +{ + uint8_t reg; + + start_ahci_device(ahci, hba_base); + +#ifdef Q35 + /* ICH9 has a register at PCI 0x92 that + * acts as a master port enabler mask. */ + reg = qpci_config_readb(ahci, 0x92); + reg |= 0x3F; + qpci_config_writeb(ahci, 0x92, reg); + assert_bit_set(qpci_config_readb(ahci, 0x92), 0x3F); +#endif +} + +/** + * Map BAR5/ABAR, and engage the PCI device. + */ +static QPCIDevice *start_ahci_device(QPCIDevice *ahci, HBA **hba_base) +{ + uint16_t data; + + /* Map AHCI's ABAR (BAR5) */ + *hba_base = qpci_iomap(ahci, 5); + + /* turns on pci.cmd.iose, pci.cmd.mse and pci.cmd.bme */ + qpci_device_enable(ahci); + +#ifdef USE_MSI + data |= PCI_COMMAND_INTX_DISABLE; + qpci_config_writew(ahci, PCI_COMMAND, data); + data = qpci_config_readw(ahci, PCI_COMMAND); +#endif + + /* These bits should now test as on. */ + data = qpci_config_readw(ahci, PCI_COMMAND); + assert_bit_set(data, PCI_COMMAND_IO); + assert_bit_set(data, PCI_COMMAND_MEMORY); + assert_bit_set(data, PCI_COMMAND_MASTER); +#ifdef USE_MSI + assert_bit_set(data, PCI_COMMAND_INTX_DISABLE); +#endif + + return ahci; +} + /*** Specification Adherence Tests ***/ /** @@ -440,6 +500,19 @@ static void test_pci_spec(void) ahci_shutdown(ahci); } +/** + * Engage the PCI AHCI device and sanity check the response. + * Perform additional PCI config space bringup for the HBA. + */ +static void test_pci_enable(void) +{ + QPCIDevice *ahci; + HBA *hba_base; + ahci_boot(&ahci); + ahci_pci_enable(ahci, &hba_base); + ahci_shutdown(ahci); +} + /******************************************************************************/ int main(int argc, char **argv) @@ -468,6 +541,7 @@ int main(int argc, char **argv) /* Run the tests */ qtest_add_func("/ahci/sanity", test_sanity); qtest_add_func("/ahci/pci_spec", test_pci_spec); + qtest_add_func("/ahci/pci_enable", test_pci_enable); ret = g_test_run(); -- 1.9.3