]> git.proxmox.com Git - mirror_qemu.git/blame - tests/megasas-test.c
Revert "audio: fix pc speaker init"
[mirror_qemu.git] / tests / megasas-test.c
CommitLineData
660174fc
PB
1/*
2 * QTest testcase for LSI MegaRAID
3 *
4 * Copyright (c) 2017 Red Hat Inc.
5 *
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.
8 */
9
10#include "qemu/osdep.h"
11#include "libqtest.h"
12#include "qemu/bswap.h"
469bb49b
PB
13#include "libqos/qgraph.h"
14#include "libqos/pci.h"
660174fc 15
469bb49b
PB
16typedef struct QMegasas QMegasas;
17
18struct QMegasas {
19 QOSGraphObject obj;
20 QPCIDevice dev;
21};
22
23static void *megasas_get_driver(void *obj, const char *interface)
660174fc 24{
469bb49b
PB
25 QMegasas *megasas = obj;
26
27 if (!g_strcmp0(interface, "pci-device")) {
28 return &megasas->dev;
660174fc
PB
29 }
30
469bb49b
PB
31 fprintf(stderr, "%s not present in megasas\n", interface);
32 g_assert_not_reached();
660174fc
PB
33}
34
469bb49b 35static void *megasas_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
660174fc 36{
469bb49b
PB
37 QMegasas *megasas = g_new0(QMegasas, 1);
38 QPCIBus *bus = pci_bus;
660174fc 39
469bb49b
PB
40 qpci_device_init(&megasas->dev, bus, addr);
41 megasas->obj.get_driver = megasas_get_driver;
660174fc 42
469bb49b 43 return &megasas->obj;
660174fc
PB
44}
45
87e459a8 46/* This used to cause a NULL pointer dereference. */
469bb49b 47static void megasas_pd_get_info_fuzz(void *obj, void *data, QGuestAllocator *alloc)
87e459a8 48{
469bb49b
PB
49 QMegasas *megasas = obj;
50 QPCIDevice *dev = &megasas->dev;
87e459a8
PB
51 QPCIBar bar;
52 uint32_t context[256];
53 uint64_t context_pa;
54 int i;
55
87e459a8
PB
56 qpci_device_enable(dev);
57 bar = qpci_iomap(dev, 0, NULL);
58
59 memset(context, 0, sizeof(context));
60 context[0] = cpu_to_le32(0x05050505);
61 context[1] = cpu_to_le32(0x01010101);
62 for (i = 2; i < ARRAY_SIZE(context); i++) {
63 context[i] = cpu_to_le32(0x41414141);
64 }
65 context[6] = cpu_to_le32(0x02020000);
66 context[7] = cpu_to_le32(0);
67
469bb49b 68 context_pa = guest_alloc(alloc, sizeof(context));
87e459a8
PB
69 memwrite(context_pa, context, sizeof(context));
70 qpci_io_writel(dev, bar, 0x40, context_pa);
87e459a8
PB
71}
72
469bb49b 73static void megasas_register_nodes(void)
660174fc 74{
469bb49b
PB
75 QOSGraphEdgeOptions opts = {
76 .extra_device_opts = "addr=04.0,id=scsi0",
77 .before_cmd_line = "-drive id=drv0,if=none,file=null-co://,format=raw",
78 .after_cmd_line = "-device scsi-hd,bus=scsi0.0,drive=drv0",
79 };
80
81 add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
82
83 qos_node_create_driver("megasas", megasas_create);
84 qos_node_consumes("megasas", "pci-bus", &opts);
85 qos_node_produces("megasas", "pci-device");
660174fc 86
469bb49b 87 qos_add_test("dcmd/pd-get-info/fuzz", "megasas", megasas_pd_get_info_fuzz, NULL);
660174fc 88}
469bb49b 89libqos_init(megasas_register_nodes);