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"
11907b5105SMarc-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
ac97_get_driver(void * obj,const char * interface)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
31146f39d7SAkihiko Odaki fprintf(stderr, "%s not present in ac97\n", interface);
321e8a1faeSThomas Huth g_assert_not_reached();
331e8a1faeSThomas Huth }
341e8a1faeSThomas Huth
ac97_create(void * pci_bus,QGuestAllocator * alloc,void * addr)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
45*031616cdSVolker Rümelin /*
46*031616cdSVolker Rümelin * This is rather a test of the audio subsystem and not an AC97 test. Test if
47*031616cdSVolker Rümelin * the audio subsystem can handle a 44100/1 upsample ratio. For some time this
48*031616cdSVolker Rümelin * used to trigger QEMU aborts.
49*031616cdSVolker Rümelin */
ac97_playback_upsample(void * obj,void * data,QGuestAllocator * alloc)50*031616cdSVolker Rümelin static void ac97_playback_upsample(void *obj, void *data, QGuestAllocator *alloc)
51*031616cdSVolker Rümelin {
52*031616cdSVolker Rümelin QAC97 *ac97 = obj;
53*031616cdSVolker Rümelin QPCIDevice *dev = &ac97->dev;
54*031616cdSVolker Rümelin QPCIBar bar0;
55*031616cdSVolker Rümelin
56*031616cdSVolker Rümelin qpci_device_enable(dev);
57*031616cdSVolker Rümelin bar0 = qpci_iomap(dev, 0, NULL);
58*031616cdSVolker Rümelin /* IOBAR0 offset 0x2c: PCM Front DAC Rate */
59*031616cdSVolker Rümelin qpci_io_writew(dev, bar0, 0x2c, 0x1);
60*031616cdSVolker Rümelin }
61*031616cdSVolker Rümelin
62*031616cdSVolker Rümelin /*
63*031616cdSVolker Rümelin * This test is similar to the playback upsample test. QEMU shouldn't abort if
64*031616cdSVolker Rümelin * asked for a 1/44100 downsample ratio.
65*031616cdSVolker Rümelin */
ac97_record_downsample(void * obj,void * data,QGuestAllocator * alloc)66*031616cdSVolker Rümelin static void ac97_record_downsample(void *obj, void *data, QGuestAllocator *alloc)
67*031616cdSVolker Rümelin {
68*031616cdSVolker Rümelin QAC97 *ac97 = obj;
69*031616cdSVolker Rümelin QPCIDevice *dev = &ac97->dev;
70*031616cdSVolker Rümelin QPCIBar bar0;
71*031616cdSVolker Rümelin
72*031616cdSVolker Rümelin qpci_device_enable(dev);
73*031616cdSVolker Rümelin bar0 = qpci_iomap(dev, 0, NULL);
74*031616cdSVolker Rümelin /* IOBAR0 offset 0x32: PCM L/R ADC Rate */
75*031616cdSVolker Rümelin qpci_io_writew(dev, bar0, 0x32, 0x1);
76*031616cdSVolker Rümelin }
77*031616cdSVolker Rümelin
ac97_register_nodes(void)781e8a1faeSThomas Huth static void ac97_register_nodes(void)
791e8a1faeSThomas Huth {
801e8a1faeSThomas Huth QOSGraphEdgeOptions opts = {
81*031616cdSVolker Rümelin .extra_device_opts = "addr=04.0,audiodev=snd0",
82*031616cdSVolker Rümelin .after_cmd_line = "-audiodev none,id=snd0"
83*031616cdSVolker Rümelin ",out.frequency=44100,in.frequency=44100",
841e8a1faeSThomas Huth };
851e8a1faeSThomas Huth add_qpci_address(&opts, &(QPCIAddress) { .devfn = QPCI_DEVFN(4, 0) });
861e8a1faeSThomas Huth
871e8a1faeSThomas Huth qos_node_create_driver("AC97", ac97_create);
881e8a1faeSThomas Huth qos_node_produces("AC97", "pci-device");
891e8a1faeSThomas Huth qos_node_consumes("AC97", "pci-bus", &opts);
90*031616cdSVolker Rümelin
91*031616cdSVolker Rümelin qos_add_test("playback_upsample", "AC97", ac97_playback_upsample, NULL);
92*031616cdSVolker Rümelin qos_add_test("record_downsample", "AC97", ac97_record_downsample, NULL);
931e8a1faeSThomas Huth }
941e8a1faeSThomas Huth
951e8a1faeSThomas Huth libqos_init(ac97_register_nodes);
96