xref: /openbmc/qemu/tests/qtest/ac97-test.c (revision 907b5105f1b9e1af1abbdbb4f2039c7ab105c001)
11e8a1faeSThomas Huth /*
21e8a1faeSThomas Huth  * QTest testcase for AC97
31e8a1faeSThomas Huth  *
41e8a1faeSThomas Huth  * Copyright (c) 2014 SUSE LINUX Products GmbH
51e8a1faeSThomas Huth  *
61e8a1faeSThomas Huth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
71e8a1faeSThomas Huth  * See the COPYING file in the top-level directory.
81e8a1faeSThomas Huth  */
91e8a1faeSThomas Huth 
101e8a1faeSThomas Huth #include "qemu/osdep.h"
11*907b5105SMarc-André Lureau #include "libqtest.h"
121e8a1faeSThomas Huth #include "qemu/module.h"
131e8a1faeSThomas Huth #include "libqos/qgraph.h"
141e8a1faeSThomas Huth #include "libqos/pci.h"
151e8a1faeSThomas Huth 
161e8a1faeSThomas Huth typedef struct QAC97 QAC97;
171e8a1faeSThomas Huth 
181e8a1faeSThomas Huth struct QAC97 {
191e8a1faeSThomas Huth     QOSGraphObject obj;
201e8a1faeSThomas Huth     QPCIDevice dev;
211e8a1faeSThomas Huth };
221e8a1faeSThomas Huth 
231e8a1faeSThomas Huth static void *ac97_get_driver(void *obj, const char *interface)
241e8a1faeSThomas Huth {
251e8a1faeSThomas Huth     QAC97 *ac97 = obj;
261e8a1faeSThomas Huth 
271e8a1faeSThomas Huth     if (!g_strcmp0(interface, "pci-device")) {
281e8a1faeSThomas Huth         return &ac97->dev;
291e8a1faeSThomas Huth     }
301e8a1faeSThomas Huth 
311e8a1faeSThomas Huth     fprintf(stderr, "%s not present in e1000e\n", interface);
321e8a1faeSThomas Huth     g_assert_not_reached();
331e8a1faeSThomas Huth }
341e8a1faeSThomas Huth 
351e8a1faeSThomas Huth static void *ac97_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
361e8a1faeSThomas Huth {
371e8a1faeSThomas Huth     QAC97 *ac97 = g_new0(QAC97, 1);
381e8a1faeSThomas Huth     QPCIBus *bus = pci_bus;
391e8a1faeSThomas Huth 
401e8a1faeSThomas Huth     qpci_device_init(&ac97->dev, bus, addr);
411e8a1faeSThomas Huth     ac97->obj.get_driver = ac97_get_driver;
421e8a1faeSThomas Huth     return &ac97->obj;
431e8a1faeSThomas Huth }
441e8a1faeSThomas Huth 
451e8a1faeSThomas Huth static void ac97_register_nodes(void)
461e8a1faeSThomas Huth {
471e8a1faeSThomas Huth     QOSGraphEdgeOptions opts = {
481e8a1faeSThomas Huth         .extra_device_opts = "addr=04.0",
491e8a1faeSThomas Huth     };
501e8a1faeSThomas Huth     add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
511e8a1faeSThomas Huth 
521e8a1faeSThomas Huth     qos_node_create_driver("AC97", ac97_create);
531e8a1faeSThomas Huth     qos_node_produces("AC97", "pci-device");
541e8a1faeSThomas Huth     qos_node_consumes("AC97", "pci-bus", &opts);
551e8a1faeSThomas Huth }
561e8a1faeSThomas Huth 
571e8a1faeSThomas Huth libqos_init(ac97_register_nodes);
58