2 * QTest testcase for acpi-erst
4 * Copyright (c) 2021 Oracle
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
10 #include "qemu/osdep.h"
11 #include <glib/gstdio.h>
12 #include "libqos/libqos-pc.h"
15 #include "hw/pci/pci.h"
17 static void save_fn(QPCIDevice
*dev
, int devfn
, void *data
)
19 QPCIDevice
**pdev
= (QPCIDevice
**) data
;
24 static QPCIDevice
*get_erst_device(QPCIBus
*pcibus
)
29 qpci_device_foreach(pcibus
,
31 PCI_DEVICE_ID_REDHAT_ACPI_ERST
,
33 g_assert(dev
!= NULL
);
38 typedef struct _ERSTState
{
40 QPCIBar reg_bar
, mem_bar
;
41 uint64_t reg_barsize
, mem_barsize
;
48 static const char *reg2str(unsigned reg
)
60 static inline uint32_t in_reg32(ERSTState
*s
, unsigned reg
)
62 const char *name
= reg2str(reg
);
65 res
= qpci_io_readl(s
->dev
, s
->reg_bar
, reg
);
66 g_test_message("*%s -> %08x", name
, res
);
71 static inline uint64_t in_reg64(ERSTState
*s
, unsigned reg
)
73 const char *name
= reg2str(reg
);
76 res
= qpci_io_readq(s
->dev
, s
->reg_bar
, reg
);
77 g_test_message("*%s -> %016" PRIx64
, name
, res
);
82 static inline void out_reg32(ERSTState
*s
, unsigned reg
, uint32_t v
)
84 const char *name
= reg2str(reg
);
86 g_test_message("%08x -> *%s", v
, name
);
87 qpci_io_writel(s
->dev
, s
->reg_bar
, reg
, v
);
90 static void cleanup_vm(ERSTState
*s
)
93 qtest_shutdown(s
->qs
);
96 static void setup_vm_cmd(ERSTState
*s
, const char *cmd
)
98 const char *arch
= qtest_get_arch();
100 if (strcmp(arch
, "i386") == 0 || strcmp(arch
, "x86_64") == 0) {
101 s
->qs
= qtest_pc_boot(cmd
);
103 g_printerr("erst-test tests are only available on x86\n");
106 s
->dev
= get_erst_device(s
->qs
->pcibus
);
108 s
->reg_bar
= qpci_iomap(s
->dev
, 0, &s
->reg_barsize
);
109 g_assert_cmpuint(s
->reg_barsize
, ==, 16);
111 s
->mem_bar
= qpci_iomap(s
->dev
, 1, &s
->mem_barsize
);
112 g_assert_cmpuint(s
->mem_barsize
, ==, 0x2000);
114 qpci_device_enable(s
->dev
);
117 static void test_acpi_erst_basic(void)
120 uint64_t log_address_range
;
121 uint64_t log_address_length
;
122 uint32_t log_address_attr
;
125 "-object memory-backend-file,"
126 "mem-path=acpi-erst.XXXXXX,"
133 out_reg32(&state
, ACTION
, 0xD);
134 log_address_range
= in_reg64(&state
, VALUE
);
135 out_reg32(&state
, ACTION
, 0xE);
136 log_address_length
= in_reg64(&state
, VALUE
);
137 out_reg32(&state
, ACTION
, 0xF);
138 log_address_attr
= in_reg32(&state
, VALUE
);
140 /* Check log_address_range is not 0, ~0 or base */
141 g_assert_cmpuint(log_address_range
, !=, 0ULL);
142 g_assert_cmpuint(log_address_range
, !=, ~0ULL);
143 g_assert_cmpuint(log_address_range
, !=, state
.reg_bar
.addr
);
144 g_assert_cmpuint(log_address_range
, ==, state
.mem_bar
.addr
);
146 /* Check log_address_length is bar1_size */
147 g_assert_cmpuint(log_address_length
, ==, state
.mem_barsize
);
149 /* Check log_address_attr is 0 */
150 g_assert_cmpuint(log_address_attr
, ==, 0);
155 int main(int argc
, char **argv
)
159 g_test_init(&argc
, &argv
, NULL
);
160 qtest_add_func("/acpi-erst/basic", test_acpi_erst_basic
);