blob: 74103efdfa01691c30f99854d6160fb5d32bfbd6 [file] [log] [blame]
Andreas Färberd7b50c02014-03-30 19:00:05 +02001/*
2 * QTest testcase for AC97
3 *
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
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
Andreas Färberd7b50c02014-03-30 19:00:05 +020010#include "qemu/osdep.h"
Marc-André Lureau907b5102022-03-30 13:39:05 +040011#include "libqtest.h"
Markus Armbruster0b8fa322019-05-23 16:35:07 +020012#include "qemu/module.h"
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020013#include "libqos/qgraph.h"
14#include "libqos/pci.h"
Andreas Färberd7b50c02014-03-30 19:00:05 +020015
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020016typedef struct QAC97 QAC97;
17
18struct QAC97 {
19 QOSGraphObject obj;
20 QPCIDevice dev;
21};
22
23static void *ac97_get_driver(void *obj, const char *interface)
Andreas Färberd7b50c02014-03-30 19:00:05 +020024{
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020025 QAC97 *ac97 = obj;
26
27 if (!g_strcmp0(interface, "pci-device")) {
28 return &ac97->dev;
29 }
30
Akihiko Odaki146f39d2022-08-29 17:33:01 +090031 fprintf(stderr, "%s not present in ac97\n", interface);
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020032 g_assert_not_reached();
Andreas Färberd7b50c02014-03-30 19:00:05 +020033}
34
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020035static void *ac97_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
Andreas Färberd7b50c02014-03-30 19:00:05 +020036{
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020037 QAC97 *ac97 = g_new0(QAC97, 1);
38 QPCIBus *bus = pci_bus;
Andreas Färberd7b50c02014-03-30 19:00:05 +020039
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020040 qpci_device_init(&ac97->dev, bus, addr);
41 ac97->obj.get_driver = ac97_get_driver;
42 return &ac97->obj;
Andreas Färberd7b50c02014-03-30 19:00:05 +020043}
Emanuele Giuseppe Esposito86dc9432018-08-17 12:01:59 +020044
45static void ac97_register_nodes(void)
46{
47 QOSGraphEdgeOptions opts = {
48 .extra_device_opts = "addr=04.0",
49 };
50 add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
51
52 qos_node_create_driver("AC97", ac97_create);
53 qos_node_produces("AC97", "pci-device");
54 qos_node_consumes("AC97", "pci-bus", &opts);
55}
56
57libqos_init(ac97_register_nodes);