tests/acpi: Update DSDT.cxl to reflect change _STA return value.
[qemu/armbru.git] / tests / qtest / ac97-test.c
blobb71bd60a8a7db32974f58bc64e0f7b03d5c1bc07
1 /*
2 * QTest testcase for AC97
4 * Copyright (c) 2014 SUSE LINUX Products GmbH
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 */
10 #include "qemu/osdep.h"
11 #include "libqtest.h"
12 #include "qemu/module.h"
13 #include "libqos/qgraph.h"
14 #include "libqos/pci.h"
16 typedef struct QAC97 QAC97;
18 struct QAC97 {
19 QOSGraphObject obj;
20 QPCIDevice dev;
23 static void *ac97_get_driver(void *obj, const char *interface)
25 QAC97 *ac97 = obj;
27 if (!g_strcmp0(interface, "pci-device")) {
28 return &ac97->dev;
31 fprintf(stderr, "%s not present in ac97\n", interface);
32 g_assert_not_reached();
35 static void *ac97_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
37 QAC97 *ac97 = g_new0(QAC97, 1);
38 QPCIBus *bus = pci_bus;
40 qpci_device_init(&ac97->dev, bus, addr);
41 ac97->obj.get_driver = ac97_get_driver;
42 return &ac97->obj;
46 * This is rather a test of the audio subsystem and not an AC97 test. Test if
47 * the audio subsystem can handle a 44100/1 upsample ratio. For some time this
48 * used to trigger QEMU aborts.
50 static void ac97_playback_upsample(void *obj, void *data, QGuestAllocator *alloc)
52 QAC97 *ac97 = obj;
53 QPCIDevice *dev = &ac97->dev;
54 QPCIBar bar0;
56 qpci_device_enable(dev);
57 bar0 = qpci_iomap(dev, 0, NULL);
58 /* IOBAR0 offset 0x2c: PCM Front DAC Rate */
59 qpci_io_writew(dev, bar0, 0x2c, 0x1);
63 * This test is similar to the playback upsample test. QEMU shouldn't abort if
64 * asked for a 1/44100 downsample ratio.
66 static void ac97_record_downsample(void *obj, void *data, QGuestAllocator *alloc)
68 QAC97 *ac97 = obj;
69 QPCIDevice *dev = &ac97->dev;
70 QPCIBar bar0;
72 qpci_device_enable(dev);
73 bar0 = qpci_iomap(dev, 0, NULL);
74 /* IOBAR0 offset 0x32: PCM L/R ADC Rate */
75 qpci_io_writew(dev, bar0, 0x32, 0x1);
78 static void ac97_register_nodes(void)
80 QOSGraphEdgeOptions opts = {
81 .extra_device_opts = "addr=04.0,audiodev=snd0",
82 .after_cmd_line = "-audiodev none,id=snd0"
83 ",out.frequency=44100,in.frequency=44100",
85 add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
87 qos_node_create_driver("AC97", ac97_create);
88 qos_node_produces("AC97", "pci-device");
89 qos_node_consumes("AC97", "pci-bus", &opts);
91 qos_add_test("playback_upsample", "AC97", ac97_playback_upsample, NULL);
92 qos_add_test("record_downsample", "AC97", ac97_record_downsample, NULL);
95 libqos_init(ac97_register_nodes);