xref: /qemu/tests/qtest/ac97-test.c (revision 86dc943f6e00af799432756c39137d663791d8d3)
1d7b50c0cSAndreas Färber /*
2d7b50c0cSAndreas Färber  * QTest testcase for AC97
3d7b50c0cSAndreas Färber  *
4d7b50c0cSAndreas Färber  * Copyright (c) 2014 SUSE LINUX Products GmbH
5d7b50c0cSAndreas Färber  *
6d7b50c0cSAndreas Färber  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7d7b50c0cSAndreas Färber  * See the COPYING file in the top-level directory.
8d7b50c0cSAndreas Färber  */
9d7b50c0cSAndreas Färber 
10d7b50c0cSAndreas Färber #include "qemu/osdep.h"
11681c28a3SPeter Maydell #include "libqtest.h"
12*86dc943fSEmanuele Giuseppe Esposito #include "libqos/qgraph.h"
13*86dc943fSEmanuele Giuseppe Esposito #include "libqos/pci.h"
14d7b50c0cSAndreas Färber 
15*86dc943fSEmanuele Giuseppe Esposito typedef struct QAC97 QAC97;
16*86dc943fSEmanuele Giuseppe Esposito 
17*86dc943fSEmanuele Giuseppe Esposito struct QAC97 {
18*86dc943fSEmanuele Giuseppe Esposito     QOSGraphObject obj;
19*86dc943fSEmanuele Giuseppe Esposito     QPCIDevice dev;
20*86dc943fSEmanuele Giuseppe Esposito };
21*86dc943fSEmanuele Giuseppe Esposito 
22*86dc943fSEmanuele Giuseppe Esposito static void *ac97_get_driver(void *obj, const char *interface)
23d7b50c0cSAndreas Färber {
24*86dc943fSEmanuele Giuseppe Esposito     QAC97 *ac97 = obj;
25*86dc943fSEmanuele Giuseppe Esposito 
26*86dc943fSEmanuele Giuseppe Esposito     if (!g_strcmp0(interface, "pci-device")) {
27*86dc943fSEmanuele Giuseppe Esposito         return &ac97->dev;
28d7b50c0cSAndreas Färber     }
29d7b50c0cSAndreas Färber 
30*86dc943fSEmanuele Giuseppe Esposito     fprintf(stderr, "%s not present in e1000e\n", interface);
31*86dc943fSEmanuele Giuseppe Esposito     g_assert_not_reached();
32d7b50c0cSAndreas Färber }
33*86dc943fSEmanuele Giuseppe Esposito 
34*86dc943fSEmanuele Giuseppe Esposito static void *ac97_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
35*86dc943fSEmanuele Giuseppe Esposito {
36*86dc943fSEmanuele Giuseppe Esposito     QAC97 *ac97 = g_new0(QAC97, 1);
37*86dc943fSEmanuele Giuseppe Esposito     QPCIBus *bus = pci_bus;
38*86dc943fSEmanuele Giuseppe Esposito 
39*86dc943fSEmanuele Giuseppe Esposito     qpci_device_init(&ac97->dev, bus, addr);
40*86dc943fSEmanuele Giuseppe Esposito     ac97->obj.get_driver = ac97_get_driver;
41*86dc943fSEmanuele Giuseppe Esposito     return &ac97->obj;
42*86dc943fSEmanuele Giuseppe Esposito }
43*86dc943fSEmanuele Giuseppe Esposito 
44*86dc943fSEmanuele Giuseppe Esposito static void ac97_register_nodes(void)
45*86dc943fSEmanuele Giuseppe Esposito {
46*86dc943fSEmanuele Giuseppe Esposito     QOSGraphEdgeOptions opts = {
47*86dc943fSEmanuele Giuseppe Esposito         .extra_device_opts = "addr=04.0",
48*86dc943fSEmanuele Giuseppe Esposito     };
49*86dc943fSEmanuele Giuseppe Esposito     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
50*86dc943fSEmanuele Giuseppe Esposito 
51*86dc943fSEmanuele Giuseppe Esposito     qos_node_create_driver("AC97", ac97_create);
52*86dc943fSEmanuele Giuseppe Esposito     qos_node_produces("AC97", "pci-device");
53*86dc943fSEmanuele Giuseppe Esposito     qos_node_consumes("AC97", "pci-bus", &opts);
54*86dc943fSEmanuele Giuseppe Esposito }
55*86dc943fSEmanuele Giuseppe Esposito 
56*86dc943fSEmanuele Giuseppe Esposito libqos_init(ac97_register_nodes);
57