alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
/* Verify that we have an AHCI device present. */
- s->dev = get_ahci_device(&s->fingerprint);
+ s->dev = get_ahci_device(s->parent->qts, &s->fingerprint);
return s;
}
qtest_start(cmdline);
g_free(cmdline);
- test_bus = qpci_init_pc(NULL);
- g_assert_nonnull(test_bus);
-
test_alloc = pc_alloc_init();
g_assert_nonnull(test_alloc);
+ test_bus = qpci_init_pc(global_qtest, test_alloc);
+ g_assert_nonnull(test_bus);
+
e1000e_device_init(test_bus, d);
}
cmdline = g_strdup_printf("-smp %d", s->num_cpus);
qtest_start(cmdline);
g_free(cmdline);
- return qpci_init_pc(NULL);
+ return qpci_init_pc(global_qtest, NULL);
}
static void test_i440fx_defaults(gconstpointer opaque)
uint16_t vendor_id, device_id;
if (!pcibus) {
- pcibus = qpci_init_pc(NULL);
+ pcibus = qpci_init_pc(global_qtest, NULL);
}
/* Find PCI device and verify it's the right one */
/**
* Locate, verify, and return a handle to the AHCI device.
*/
-QPCIDevice *get_ahci_device(uint32_t *fingerprint)
+QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint)
{
QPCIDevice *ahci;
uint32_t ahci_fingerprint;
QPCIBus *pcibus;
- pcibus = qpci_init_pc(NULL);
+ pcibus = qpci_init_pc(qts, NULL);
/* Find the AHCI PCI device and verify it's the right one. */
ahci = qpci_device_find(pcibus, QPCI_DEVFN(0x1F, 0x02));
void ahci_clean_mem(AHCIQState *ahci);
/* Device management */
-QPCIDevice *get_ahci_device(uint32_t *fingerprint);
+QPCIDevice *get_ahci_device(QTestState *qts, uint32_t *fingerprint);
void free_ahci_device(QPCIDevice *dev);
void ahci_pci_enable(AHCIQState *ahci);
void start_ahci_device(AHCIQState *ahci);
{
char *cmdline;
- struct QOSState *qs = g_new(QOSState, 1);
+ QOSState *qs = g_new0(QOSState, 1);
cmdline = g_strdup_vprintf(cmdline_fmt, ap);
qs->qts = qtest_start(cmdline);
qs->ops = ops;
if (ops) {
- if (ops->init_allocator) {
- qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
- }
- if (ops->qpci_init && qs->alloc) {
- qs->pcibus = ops->qpci_init(qs->alloc);
- }
+ qs->alloc = ops->init_allocator(ALLOC_NO_FLAGS);
+ qs->pcibus = ops->qpci_init(qs->qts, qs->alloc);
}
g_free(cmdline);
typedef struct QOSOps {
QGuestAllocator *(*init_allocator)(QAllocOpts);
void (*uninit_allocator)(QGuestAllocator *);
- QPCIBus *(*qpci_init)(QGuestAllocator *alloc);
+ QPCIBus *(*qpci_init)(QTestState *qts, QGuestAllocator *alloc);
void (*qpci_free)(QPCIBus *bus);
void (*shutdown)(QOSState *);
} QOSOps;
outl(0xcfc, value);
}
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc)
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc)
{
- QPCIBusPC *ret;
+ QPCIBusPC *ret = g_new0(QPCIBusPC, 1);
- ret = g_malloc(sizeof(*ret));
+ assert(qts);
ret->bus.pio_readb = qpci_pc_pio_readb;
ret->bus.pio_readw = qpci_pc_pio_readw;
ret->bus.config_writew = qpci_pc_config_writew;
ret->bus.config_writel = qpci_pc_config_writel;
+ ret->bus.qts = qts;
ret->bus.pio_alloc_ptr = 0xc000;
ret->bus.mmio_alloc_ptr = 0xE0000000;
ret->bus.mmio_limit = 0x100000000ULL;
#include "libqos/pci.h"
#include "libqos/malloc.h"
-QPCIBus *qpci_init_pc(QGuestAllocator *alloc);
+QPCIBus *qpci_init_pc(QTestState *qts, QGuestAllocator *alloc);
void qpci_free_pc(QPCIBus *bus);
#endif
#define SPAPR_PCI_MMIO32_WIN_SIZE 0x80000000 /* 2 GiB */
#define SPAPR_PCI_IO_WIN_SIZE 0x10000
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc)
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc)
{
- QPCIBusSPAPR *ret;
+ QPCIBusSPAPR *ret = g_new0(QPCIBusSPAPR, 1);
- ret = g_malloc(sizeof(*ret));
+ assert(qts);
ret->alloc = alloc;
ret->mmio32.pci_base = SPAPR_PCI_MMIO32_WIN_SIZE;
ret->mmio32.size = SPAPR_PCI_MMIO32_WIN_SIZE;
+ ret->bus.qts = qts;
ret->bus.pio_alloc_ptr = 0xc000;
ret->bus.mmio_alloc_ptr = ret->mmio32.pci_base;
ret->bus.mmio_limit = ret->mmio32.pci_base + ret->mmio32.size;
#include "libqos/malloc.h"
#include "libqos/pci.h"
-QPCIBus *qpci_init_spapr(QGuestAllocator *alloc);
+QPCIBus *qpci_init_spapr(QTestState *qts, QGuestAllocator *alloc);
void qpci_free_spapr(QPCIBus *bus);
#endif
void (*config_writel)(QPCIBus *bus, int devfn,
uint8_t offset, uint32_t value);
+ QTestState *qts;
uint16_t pio_alloc_ptr;
uint64_t mmio_alloc_ptr, mmio_limit;
};
qtest_start("-M q35");
- pcibus = qpci_init_pc(NULL);
+ pcibus = qpci_init_pc(global_qtest, NULL);
g_assert(pcibus != NULL);
pcidev = qpci_device_find(pcibus, 0);
g_free(cmdline);
/* locate the DRAM controller */
- pcibus = qpci_init_pc(NULL);
+ pcibus = qpci_init_pc(global_qtest, NULL);
g_assert(pcibus != NULL);
pcidev = qpci_device_find(pcibus, 0);
g_assert(pcidev != NULL);
{
QPCIDevice *dev;
- pcibus = qpci_init_pc(NULL);
+ pcibus = qpci_init_pc(global_qtest, NULL);
qpci_device_foreach(pcibus, 0x10ec, 0x8139, save_fn, &dev);
g_assert(dev != NULL);
{
int ret;
+ qtest_start("-device rtl8139");
+
g_test_init(&argc, &argv, NULL);
qtest_add_func("/rtl8139/nop", nop);
qtest_add_func("/rtl8139/timer", test_init);
- qtest_start("-device rtl8139");
ret = g_test_run();
qtest_end();
global_qtest = qtest_startf("-machine %s -device sdhci-pci",
test->machine);
- s->pci.bus = qpci_init_pc(NULL);
+ s->pci.bus = qpci_init_pc(global_qtest, NULL);
/* Find PCI device and verify it's the right one */
s->pci.dev = qpci_device_find(s->pci.bus, QPCI_DEVFN(4, 0));
global_qtest = qs;
qtest_irq_intercept_in(qs, "ioapic");
- d->bus = qpci_init_pc(NULL);
+ d->bus = qpci_init_pc(qs, NULL);
d->dev = qpci_device_find(d->bus, QPCI_DEVFN(0x1f, 0x00));
g_assert(d->dev != NULL);
static void test_init(void)
{
- pcibus = qpci_init_pc(NULL);
+ pcibus = qpci_init_pc(global_qtest, NULL);
g_assert(pcibus != NULL);
qusb_pci_init_one(pcibus, &uhci1, QPCI_DEVFN(0x1d, 0), 4);
uint32_t features;
int i;
- s->bus = qpci_init_pc(NULL);
+ s->bus = qpci_init_pc(global_qtest, NULL);
g_assert_nonnull(s->bus);
s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);