11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth * qtest I440FX test case
31e8a1faeSThomas Huth *
41e8a1faeSThomas Huth * Copyright IBM, Corp. 2012-2013
51e8a1faeSThomas Huth * Copyright Red Hat, Inc. 2013
61e8a1faeSThomas Huth *
71e8a1faeSThomas Huth * Authors:
81e8a1faeSThomas Huth * Anthony Liguori <aliguori@us.ibm.com>
91e8a1faeSThomas Huth * Laszlo Ersek <lersek@redhat.com>
101e8a1faeSThomas Huth *
111e8a1faeSThomas Huth * This work is licensed under the terms of the GNU GPL, version 2 or later.
121e8a1faeSThomas Huth * See the COPYING file in the top-level directory.
131e8a1faeSThomas Huth */
141e8a1faeSThomas Huth
151e8a1faeSThomas Huth #include "qemu/osdep.h"
161e8a1faeSThomas Huth
171e8a1faeSThomas Huth #include "libqtest-single.h"
181e8a1faeSThomas Huth #include "libqos/pci.h"
191e8a1faeSThomas Huth #include "libqos/pci-pc.h"
201e8a1faeSThomas Huth #include "hw/pci/pci_regs.h"
211e8a1faeSThomas Huth
221e8a1faeSThomas Huth #define BROKEN 1
231e8a1faeSThomas Huth
241e8a1faeSThomas Huth typedef struct TestData
251e8a1faeSThomas Huth {
261e8a1faeSThomas Huth int num_cpus;
271e8a1faeSThomas Huth } TestData;
281e8a1faeSThomas Huth
291e8a1faeSThomas Huth typedef struct FirmwareTestFixture {
301e8a1faeSThomas Huth /* decides whether we're testing -bios or -pflash */
311e8a1faeSThomas Huth bool is_bios;
321e8a1faeSThomas Huth } FirmwareTestFixture;
331e8a1faeSThomas Huth
test_start_get_bus(const TestData * s)341e8a1faeSThomas Huth static QPCIBus *test_start_get_bus(const TestData *s)
351e8a1faeSThomas Huth {
361e8a1faeSThomas Huth char *cmdline;
371e8a1faeSThomas Huth
38fedcc379SDr. David Alan Gilbert cmdline = g_strdup_printf("-machine pc -smp %d", s->num_cpus);
391e8a1faeSThomas Huth qtest_start(cmdline);
401e8a1faeSThomas Huth g_free(cmdline);
411e8a1faeSThomas Huth return qpci_new_pc(global_qtest, NULL);
421e8a1faeSThomas Huth }
431e8a1faeSThomas Huth
test_i440fx_defaults(gconstpointer opaque)441e8a1faeSThomas Huth static void test_i440fx_defaults(gconstpointer opaque)
451e8a1faeSThomas Huth {
461e8a1faeSThomas Huth const TestData *s = opaque;
471e8a1faeSThomas Huth QPCIBus *bus;
481e8a1faeSThomas Huth QPCIDevice *dev;
491e8a1faeSThomas Huth uint32_t value;
501e8a1faeSThomas Huth
511e8a1faeSThomas Huth bus = test_start_get_bus(s);
521e8a1faeSThomas Huth dev = qpci_device_find(bus, QPCI_DEVFN(0, 0));
531e8a1faeSThomas Huth g_assert(dev != NULL);
541e8a1faeSThomas Huth
551e8a1faeSThomas Huth /* 3.2.2 */
561e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readw(dev, PCI_VENDOR_ID), ==, 0x8086);
571e8a1faeSThomas Huth /* 3.2.3 */
581e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readw(dev, PCI_DEVICE_ID), ==, 0x1237);
591e8a1faeSThomas Huth #ifndef BROKEN
601e8a1faeSThomas Huth /* 3.2.4 */
611e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readw(dev, PCI_COMMAND), ==, 0x0006);
621e8a1faeSThomas Huth /* 3.2.5 */
631e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readw(dev, PCI_STATUS), ==, 0x0280);
641e8a1faeSThomas Huth #endif
651e8a1faeSThomas Huth /* 3.2.7 */
661e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, PCI_CLASS_PROG), ==, 0x00);
671e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readw(dev, PCI_CLASS_DEVICE), ==, 0x0600);
681e8a1faeSThomas Huth /* 3.2.8 */
691e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, PCI_LATENCY_TIMER), ==, 0x00);
701e8a1faeSThomas Huth /* 3.2.9 */
711e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, PCI_HEADER_TYPE), ==, 0x00);
721e8a1faeSThomas Huth /* 3.2.10 */
731e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, PCI_BIST), ==, 0x00);
741e8a1faeSThomas Huth
751e8a1faeSThomas Huth /* 3.2.11 */
761e8a1faeSThomas Huth value = qpci_config_readw(dev, 0x50); /* PMCCFG */
771e8a1faeSThomas Huth if (s->num_cpus == 1) { /* WPE */
781e8a1faeSThomas Huth g_assert(!(value & (1 << 15)));
791e8a1faeSThomas Huth } else {
801e8a1faeSThomas Huth g_assert((value & (1 << 15)));
811e8a1faeSThomas Huth }
821e8a1faeSThomas Huth
831e8a1faeSThomas Huth g_assert(!(value & (1 << 6))); /* EPTE */
841e8a1faeSThomas Huth
851e8a1faeSThomas Huth /* 3.2.12 */
861e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x52), ==, 0x00); /* DETURBO */
871e8a1faeSThomas Huth /* 3.2.13 */
881e8a1faeSThomas Huth #ifndef BROKEN
891e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x53), ==, 0x80); /* DBC */
901e8a1faeSThomas Huth #endif
911e8a1faeSThomas Huth /* 3.2.14 */
921e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x54), ==, 0x00); /* AXC */
931e8a1faeSThomas Huth /* 3.2.15 */
941e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readw(dev, 0x55), ==, 0x0000); /* DRT */
951e8a1faeSThomas Huth #ifndef BROKEN
961e8a1faeSThomas Huth /* 3.2.16 */
971e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x57), ==, 0x01); /* DRAMC */
981e8a1faeSThomas Huth /* 3.2.17 */
991e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x58), ==, 0x10); /* DRAMT */
1001e8a1faeSThomas Huth #endif
1011e8a1faeSThomas Huth /* 3.2.18 */
1021e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x59), ==, 0x00); /* PAM0 */
1031e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x5A), ==, 0x00); /* PAM1 */
1041e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x5B), ==, 0x00); /* PAM2 */
1051e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x5C), ==, 0x00); /* PAM3 */
1061e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x5D), ==, 0x00); /* PAM4 */
1071e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x5E), ==, 0x00); /* PAM5 */
1081e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x5F), ==, 0x00); /* PAM6 */
1091e8a1faeSThomas Huth #ifndef BROKEN
1101e8a1faeSThomas Huth /* 3.2.19 */
1111e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x60), ==, 0x01); /* DRB0 */
1121e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x61), ==, 0x01); /* DRB1 */
1131e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x62), ==, 0x01); /* DRB2 */
1141e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x63), ==, 0x01); /* DRB3 */
1151e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x64), ==, 0x01); /* DRB4 */
1161e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x65), ==, 0x01); /* DRB5 */
1171e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x66), ==, 0x01); /* DRB6 */
1181e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x67), ==, 0x01); /* DRB7 */
1191e8a1faeSThomas Huth #endif
1201e8a1faeSThomas Huth /* 3.2.20 */
1211e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x68), ==, 0x00); /* FDHC */
1221e8a1faeSThomas Huth /* 3.2.21 */
1231e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x70), ==, 0x00); /* MTT */
1241e8a1faeSThomas Huth #ifndef BROKEN
1251e8a1faeSThomas Huth /* 3.2.22 */
1261e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x71), ==, 0x10); /* CLT */
1271e8a1faeSThomas Huth #endif
1281e8a1faeSThomas Huth /* 3.2.23 */
1291e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x72), ==, 0x02); /* SMRAM */
1301e8a1faeSThomas Huth /* 3.2.24 */
1311e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x90), ==, 0x00); /* ERRCMD */
1321e8a1faeSThomas Huth /* 3.2.25 */
1331e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x91), ==, 0x00); /* ERRSTS */
1341e8a1faeSThomas Huth /* 3.2.26 */
1351e8a1faeSThomas Huth g_assert_cmpint(qpci_config_readb(dev, 0x93), ==, 0x00); /* TRC */
1361e8a1faeSThomas Huth
1371e8a1faeSThomas Huth g_free(dev);
1381e8a1faeSThomas Huth qpci_free_pc(bus);
1391e8a1faeSThomas Huth qtest_end();
1401e8a1faeSThomas Huth }
1411e8a1faeSThomas Huth
1421e8a1faeSThomas Huth #define PAM_RE 1
1431e8a1faeSThomas Huth #define PAM_WE 2
1441e8a1faeSThomas Huth
pam_set(QPCIDevice * dev,int index,int flags)1451e8a1faeSThomas Huth static void pam_set(QPCIDevice *dev, int index, int flags)
1461e8a1faeSThomas Huth {
1471e8a1faeSThomas Huth int regno = 0x59 + (index / 2);
1481e8a1faeSThomas Huth uint8_t reg;
1491e8a1faeSThomas Huth
1501e8a1faeSThomas Huth reg = qpci_config_readb(dev, regno);
1511e8a1faeSThomas Huth if (index & 1) {
1521e8a1faeSThomas Huth reg = (reg & 0x0F) | (flags << 4);
1531e8a1faeSThomas Huth } else {
1541e8a1faeSThomas Huth reg = (reg & 0xF0) | flags;
1551e8a1faeSThomas Huth }
1561e8a1faeSThomas Huth qpci_config_writeb(dev, regno, reg);
1571e8a1faeSThomas Huth }
1581e8a1faeSThomas Huth
verify_area(uint32_t start,uint32_t end,uint8_t value)1591e8a1faeSThomas Huth static gboolean verify_area(uint32_t start, uint32_t end, uint8_t value)
1601e8a1faeSThomas Huth {
1611e8a1faeSThomas Huth uint32_t size = end - start + 1;
1621e8a1faeSThomas Huth gboolean ret = TRUE;
1631e8a1faeSThomas Huth uint8_t *data;
1641e8a1faeSThomas Huth int i;
1651e8a1faeSThomas Huth
1661e8a1faeSThomas Huth data = g_malloc0(size);
1671e8a1faeSThomas Huth memread(start, data, size);
1681e8a1faeSThomas Huth
1691e8a1faeSThomas Huth g_test_message("verify_area: data[0] = 0x%x", data[0]);
1701e8a1faeSThomas Huth
1711e8a1faeSThomas Huth for (i = 0; i < size; i++) {
1721e8a1faeSThomas Huth if (data[i] != value) {
1731e8a1faeSThomas Huth ret = FALSE;
1741e8a1faeSThomas Huth break;
1751e8a1faeSThomas Huth }
1761e8a1faeSThomas Huth }
1771e8a1faeSThomas Huth
1781e8a1faeSThomas Huth g_free(data);
1791e8a1faeSThomas Huth
1801e8a1faeSThomas Huth return ret;
1811e8a1faeSThomas Huth }
1821e8a1faeSThomas Huth
write_area(uint32_t start,uint32_t end,uint8_t value)1831e8a1faeSThomas Huth static void write_area(uint32_t start, uint32_t end, uint8_t value)
1841e8a1faeSThomas Huth {
1851e8a1faeSThomas Huth uint32_t size = end - start + 1;
1861e8a1faeSThomas Huth uint8_t *data;
1871e8a1faeSThomas Huth
1881e8a1faeSThomas Huth data = g_malloc(size);
1891e8a1faeSThomas Huth memset(data, value, size);
1901e8a1faeSThomas Huth memwrite(start, data, size);
1911e8a1faeSThomas Huth
1921e8a1faeSThomas Huth g_free(data);
1931e8a1faeSThomas Huth }
1941e8a1faeSThomas Huth
test_i440fx_pam(gconstpointer opaque)1951e8a1faeSThomas Huth static void test_i440fx_pam(gconstpointer opaque)
1961e8a1faeSThomas Huth {
1971e8a1faeSThomas Huth const TestData *s = opaque;
1981e8a1faeSThomas Huth QPCIBus *bus;
1991e8a1faeSThomas Huth QPCIDevice *dev;
2001e8a1faeSThomas Huth int i;
2011e8a1faeSThomas Huth static struct {
2021e8a1faeSThomas Huth uint32_t start;
2031e8a1faeSThomas Huth uint32_t end;
2041e8a1faeSThomas Huth } pam_area[] = {
2051e8a1faeSThomas Huth { 0, 0 }, /* Reserved */
2061e8a1faeSThomas Huth { 0xF0000, 0xFFFFF }, /* BIOS Area */
2071e8a1faeSThomas Huth { 0xC0000, 0xC3FFF }, /* Option ROM */
2081e8a1faeSThomas Huth { 0xC4000, 0xC7FFF }, /* Option ROM */
2091e8a1faeSThomas Huth { 0xC8000, 0xCBFFF }, /* Option ROM */
2101e8a1faeSThomas Huth { 0xCC000, 0xCFFFF }, /* Option ROM */
2111e8a1faeSThomas Huth { 0xD0000, 0xD3FFF }, /* Option ROM */
2121e8a1faeSThomas Huth { 0xD4000, 0xD7FFF }, /* Option ROM */
2131e8a1faeSThomas Huth { 0xD8000, 0xDBFFF }, /* Option ROM */
2141e8a1faeSThomas Huth { 0xDC000, 0xDFFFF }, /* Option ROM */
2151e8a1faeSThomas Huth { 0xE0000, 0xE3FFF }, /* BIOS Extension */
2161e8a1faeSThomas Huth { 0xE4000, 0xE7FFF }, /* BIOS Extension */
2171e8a1faeSThomas Huth { 0xE8000, 0xEBFFF }, /* BIOS Extension */
2181e8a1faeSThomas Huth { 0xEC000, 0xEFFFF }, /* BIOS Extension */
2191e8a1faeSThomas Huth };
2201e8a1faeSThomas Huth
2211e8a1faeSThomas Huth bus = test_start_get_bus(s);
2221e8a1faeSThomas Huth dev = qpci_device_find(bus, QPCI_DEVFN(0, 0));
2231e8a1faeSThomas Huth g_assert(dev != NULL);
2241e8a1faeSThomas Huth
2251e8a1faeSThomas Huth for (i = 0; i < ARRAY_SIZE(pam_area); i++) {
2261e8a1faeSThomas Huth if (pam_area[i].start == pam_area[i].end) {
2271e8a1faeSThomas Huth continue;
2281e8a1faeSThomas Huth }
2291e8a1faeSThomas Huth
2301e8a1faeSThomas Huth g_test_message("Checking area 0x%05x..0x%05x",
2311e8a1faeSThomas Huth pam_area[i].start, pam_area[i].end);
2321e8a1faeSThomas Huth /* Switch to RE for the area */
2331e8a1faeSThomas Huth pam_set(dev, i, PAM_RE);
2341e8a1faeSThomas Huth /* Verify the RAM is all zeros */
2351e8a1faeSThomas Huth g_assert(verify_area(pam_area[i].start, pam_area[i].end, 0));
2361e8a1faeSThomas Huth
2371e8a1faeSThomas Huth /* Switch to WE for the area */
2381e8a1faeSThomas Huth pam_set(dev, i, PAM_RE | PAM_WE);
2391e8a1faeSThomas Huth /* Write out a non-zero mask to the full area */
2401e8a1faeSThomas Huth write_area(pam_area[i].start, pam_area[i].end, 0x42);
2411e8a1faeSThomas Huth
2421e8a1faeSThomas Huth #ifndef BROKEN
2431e8a1faeSThomas Huth /* QEMU only supports a limited form of PAM */
2441e8a1faeSThomas Huth
2451e8a1faeSThomas Huth /* Switch to !RE for the area */
2461e8a1faeSThomas Huth pam_set(dev, i, PAM_WE);
2471e8a1faeSThomas Huth /* Verify the area is not our mask */
2481e8a1faeSThomas Huth g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x42));
2491e8a1faeSThomas Huth #endif
2501e8a1faeSThomas Huth
2511e8a1faeSThomas Huth /* Verify the area is our new mask */
2521e8a1faeSThomas Huth g_assert(verify_area(pam_area[i].start, pam_area[i].end, 0x42));
2531e8a1faeSThomas Huth
2541e8a1faeSThomas Huth /* Write out a new mask */
2551e8a1faeSThomas Huth write_area(pam_area[i].start, pam_area[i].end, 0x82);
2561e8a1faeSThomas Huth
2571e8a1faeSThomas Huth #ifndef BROKEN
2581e8a1faeSThomas Huth /* QEMU only supports a limited form of PAM */
2591e8a1faeSThomas Huth
2601e8a1faeSThomas Huth /* Verify the area is not our mask */
2611e8a1faeSThomas Huth g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82));
2621e8a1faeSThomas Huth
2631e8a1faeSThomas Huth /* Switch to RE for the area */
2641e8a1faeSThomas Huth pam_set(dev, i, PAM_RE | PAM_WE);
2651e8a1faeSThomas Huth #endif
2661e8a1faeSThomas Huth /* Verify the area is our new mask */
2671e8a1faeSThomas Huth g_assert(verify_area(pam_area[i].start, pam_area[i].end, 0x82));
2681e8a1faeSThomas Huth
2691e8a1faeSThomas Huth /* Reset area */
2701e8a1faeSThomas Huth pam_set(dev, i, 0);
2711e8a1faeSThomas Huth
2721e8a1faeSThomas Huth /* Verify the area is not our new mask */
2731e8a1faeSThomas Huth g_assert(!verify_area(pam_area[i].start, pam_area[i].end, 0x82));
2741e8a1faeSThomas Huth }
2751e8a1faeSThomas Huth
2761e8a1faeSThomas Huth g_free(dev);
2771e8a1faeSThomas Huth qpci_free_pc(bus);
2781e8a1faeSThomas Huth qtest_end();
2791e8a1faeSThomas Huth }
2801e8a1faeSThomas Huth
2811e8a1faeSThomas Huth #define BLOB_SIZE ((size_t)65536)
2821e8a1faeSThomas Huth #define ISA_BIOS_MAXSZ ((size_t)(128 * 1024))
2831e8a1faeSThomas Huth
284*3039fd4bSBin Meng /*
285*3039fd4bSBin Meng * Create a blob file, and return its absolute pathname as a dynamically
2861e8a1faeSThomas Huth * allocated string.
2871e8a1faeSThomas Huth * The file is closed before the function returns.
288*3039fd4bSBin Meng * In case of error, the function aborts and prints the error message.
2891e8a1faeSThomas Huth */
create_blob_file(void)2901e8a1faeSThomas Huth static char *create_blob_file(void)
2911e8a1faeSThomas Huth {
292*3039fd4bSBin Meng int i, fd;
2931e8a1faeSThomas Huth char *pathname;
2941e8a1faeSThomas Huth GError *error = NULL;
295*3039fd4bSBin Meng g_autofree uint8_t *buf = g_malloc(BLOB_SIZE);
2961e8a1faeSThomas Huth
2971e8a1faeSThomas Huth fd = g_file_open_tmp("blob_XXXXXX", &pathname, &error);
298*3039fd4bSBin Meng g_assert_no_error(error);
2991e8a1faeSThomas Huth close(fd);
300*3039fd4bSBin Meng
301*3039fd4bSBin Meng for (i = 0; i < BLOB_SIZE; i++) {
302*3039fd4bSBin Meng buf[i] = i;
3031e8a1faeSThomas Huth }
3041e8a1faeSThomas Huth
305*3039fd4bSBin Meng g_file_set_contents(pathname, (char *)buf, BLOB_SIZE, &error);
306*3039fd4bSBin Meng g_assert_no_error(error);
307*3039fd4bSBin Meng
308*3039fd4bSBin Meng return pathname;
3091e8a1faeSThomas Huth }
3101e8a1faeSThomas Huth
test_i440fx_firmware(FirmwareTestFixture * fixture,gconstpointer user_data)3111e8a1faeSThomas Huth static void test_i440fx_firmware(FirmwareTestFixture *fixture,
3121e8a1faeSThomas Huth gconstpointer user_data)
3131e8a1faeSThomas Huth {
3141e8a1faeSThomas Huth char *fw_pathname, *cmdline;
3151e8a1faeSThomas Huth uint8_t *buf;
3161e8a1faeSThomas Huth size_t i, isa_bios_size;
3171e8a1faeSThomas Huth
3181e8a1faeSThomas Huth fw_pathname = create_blob_file();
3191e8a1faeSThomas Huth g_assert(fw_pathname != NULL);
3201e8a1faeSThomas Huth
3211e8a1faeSThomas Huth /* Better hope the user didn't put metacharacters in TMPDIR and co. */
3221e8a1faeSThomas Huth cmdline = g_strdup_printf("-S %s%s", fixture->is_bios
3231e8a1faeSThomas Huth ? "-bios "
3241e8a1faeSThomas Huth : "-drive if=pflash,format=raw,file=",
3251e8a1faeSThomas Huth fw_pathname);
3261e8a1faeSThomas Huth g_test_message("qemu cmdline: %s", cmdline);
3271e8a1faeSThomas Huth qtest_start(cmdline);
3281e8a1faeSThomas Huth g_free(cmdline);
3291e8a1faeSThomas Huth
3301e8a1faeSThomas Huth /* QEMU has loaded the firmware (because qtest_start() only returns after
3311e8a1faeSThomas Huth * the QMP handshake completes). We must unlink the firmware blob right
3321e8a1faeSThomas Huth * here, because any assertion firing below would leak it in the
3331e8a1faeSThomas Huth * filesystem. This is also the reason why we recreate the blob every time
3341e8a1faeSThomas Huth * this function is invoked.
3351e8a1faeSThomas Huth */
3361e8a1faeSThomas Huth unlink(fw_pathname);
3371e8a1faeSThomas Huth g_free(fw_pathname);
3381e8a1faeSThomas Huth
3391e8a1faeSThomas Huth /* check below 4G */
3401e8a1faeSThomas Huth buf = g_malloc0(BLOB_SIZE);
3411e8a1faeSThomas Huth memread(0x100000000ULL - BLOB_SIZE, buf, BLOB_SIZE);
3421e8a1faeSThomas Huth for (i = 0; i < BLOB_SIZE; ++i) {
3431e8a1faeSThomas Huth g_assert_cmphex(buf[i], ==, (uint8_t)i);
3441e8a1faeSThomas Huth }
3451e8a1faeSThomas Huth
3461e8a1faeSThomas Huth /* check in ISA space too */
3471e8a1faeSThomas Huth memset(buf, 0, BLOB_SIZE);
3481e8a1faeSThomas Huth isa_bios_size = ISA_BIOS_MAXSZ < BLOB_SIZE ? ISA_BIOS_MAXSZ : BLOB_SIZE;
3491e8a1faeSThomas Huth memread(0x100000 - isa_bios_size, buf, isa_bios_size);
3501e8a1faeSThomas Huth for (i = 0; i < isa_bios_size; ++i) {
3511e8a1faeSThomas Huth g_assert_cmphex(buf[i], ==,
3521e8a1faeSThomas Huth (uint8_t)((BLOB_SIZE - isa_bios_size) + i));
3531e8a1faeSThomas Huth }
3541e8a1faeSThomas Huth
3551e8a1faeSThomas Huth g_free(buf);
3561e8a1faeSThomas Huth qtest_end();
3571e8a1faeSThomas Huth }
3581e8a1faeSThomas Huth
add_firmware_test(const char * testpath,void (* setup_fixture)(FirmwareTestFixture * f,gconstpointer test_data))3591e8a1faeSThomas Huth static void add_firmware_test(const char *testpath,
3601e8a1faeSThomas Huth void (*setup_fixture)(FirmwareTestFixture *f,
3611e8a1faeSThomas Huth gconstpointer test_data))
3621e8a1faeSThomas Huth {
3631e8a1faeSThomas Huth qtest_add(testpath, FirmwareTestFixture, NULL, setup_fixture,
3641e8a1faeSThomas Huth test_i440fx_firmware, NULL);
3651e8a1faeSThomas Huth }
3661e8a1faeSThomas Huth
request_bios(FirmwareTestFixture * fixture,gconstpointer user_data)3671e8a1faeSThomas Huth static void request_bios(FirmwareTestFixture *fixture,
3681e8a1faeSThomas Huth gconstpointer user_data)
3691e8a1faeSThomas Huth {
3701e8a1faeSThomas Huth fixture->is_bios = true;
3711e8a1faeSThomas Huth }
3721e8a1faeSThomas Huth
request_pflash(FirmwareTestFixture * fixture,gconstpointer user_data)3731e8a1faeSThomas Huth static void request_pflash(FirmwareTestFixture *fixture,
3741e8a1faeSThomas Huth gconstpointer user_data)
3751e8a1faeSThomas Huth {
3761e8a1faeSThomas Huth fixture->is_bios = false;
3771e8a1faeSThomas Huth }
3781e8a1faeSThomas Huth
main(int argc,char ** argv)3791e8a1faeSThomas Huth int main(int argc, char **argv)
3801e8a1faeSThomas Huth {
3811e8a1faeSThomas Huth TestData data;
3821e8a1faeSThomas Huth
3831e8a1faeSThomas Huth g_test_init(&argc, &argv, NULL);
3841e8a1faeSThomas Huth
3851e8a1faeSThomas Huth data.num_cpus = 1;
3861e8a1faeSThomas Huth
3871e8a1faeSThomas Huth qtest_add_data_func("i440fx/defaults", &data, test_i440fx_defaults);
3881e8a1faeSThomas Huth qtest_add_data_func("i440fx/pam", &data, test_i440fx_pam);
3891e8a1faeSThomas Huth add_firmware_test("i440fx/firmware/bios", request_bios);
3901e8a1faeSThomas Huth add_firmware_test("i440fx/firmware/pflash", request_pflash);
3911e8a1faeSThomas Huth
3921e8a1faeSThomas Huth return g_test_run();
3931e8a1faeSThomas Huth }
394