[Beignet] [PATCH] virtio-audio: add virtio audio device emulation
xionghu.luo at intel.com
xionghu.luo at intel.com
Tue Aug 29 01:33:48 UTC 2017
From: Luo Xionghu <xionghu.luo at intel.com>
this patch only add audio device pci registration.
need add audio part to call audio Backend driver later.
Signed-off-by: Luo Xionghu <xionghu.luo at intel.com>
---
hw/virtio/Makefile.objs | 1 +
hw/virtio/virtio-audio.c | 150 ++++++++++++++++++++++++++
hw/virtio/virtio-pci.c | 49 +++++++++
hw/virtio/virtio-pci.h | 13 +++
include/hw/pci/pci.h | 1 +
include/hw/virtio/virtio-audio.h | 61 +++++++++++
include/standard-headers/linux/virtio_audio.h | 9 ++
include/standard-headers/linux/virtio_ids.h | 1 +
8 files changed, 285 insertions(+)
create mode 100644 hw/virtio/virtio-audio.c
create mode 100644 include/hw/virtio/virtio-audio.h
create mode 100644 include/standard-headers/linux/virtio_audio.h
diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs
index 765d363c1f..a1f3136fd4 100644
--- a/hw/virtio/Makefile.objs
+++ b/hw/virtio/Makefile.objs
@@ -9,6 +9,7 @@ obj-$(CONFIG_LINUX) += vhost.o vhost-backend.o vhost-user.o
obj-$(CONFIG_VHOST_VSOCK) += vhost-vsock.o
obj-y += virtio-crypto.o
obj-$(CONFIG_VIRTIO_PCI) += virtio-crypto-pci.o
+obj-y += virtio-audio.o
endif
common-obj-$(call lnot,$(CONFIG_LINUX)) += vhost-stub.o
diff --git a/hw/virtio/virtio-audio.c b/hw/virtio/virtio-audio.c
new file mode 100644
index 0000000000..784fed1e12
--- /dev/null
+++ b/hw/virtio/virtio-audio.c
@@ -0,0 +1,150 @@
+/*
+ * Virtio audio Support
+ *
+ * Copyright (c) 2017 Intel Corperation.
+ *
+ * Authors:
+ * Luo Xionghu<xionghu.luo at intel.com>
+ * Liam Girdwood <liam.r.girdwood at linux.intel.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version. See the COPYING file in the
+ * top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "qemu/iov.h"
+#include "qemu/timer.h"
+#include "qemu-common.h"
+#include "hw/virtio/virtio.h"
+#include "hw/i386/pc.h"
+#include "hw/virtio/virtio-audio.h"
+#include "sysemu/kvm.h"
+#include "exec/address-spaces.h"
+#include "qapi/visitor.h"
+#include "qapi-event.h"
+#include "trace.h"
+
+#include "hw/virtio/virtio-bus.h"
+#include "hw/virtio/virtio-access.h"
+
+static void virtio_audio_reset(VirtIODevice *vdev)
+{
+
+}
+
+static void virtio_audio_set_status(VirtIODevice *vdev, uint8_t status)
+{
+
+}
+
+static uint64_t virtio_audio_get_features(VirtIODevice *vdev, uint64_t f,
+ Error **errp)
+{
+
+ return 0;
+}
+
+static void virtio_audio_set_config(VirtIODevice *vdev,
+ const uint8_t *config_data)
+{
+
+}
+
+static void virtio_audio_get_config(VirtIODevice *vdev, uint8_t *config_data)
+{
+
+}
+
+static const VMStateDescription vmstate_virtio_audio = {
+ .name = "virtio-audio",
+ .minimum_version_id = 1,
+ .version_id = 1,
+ .fields = (VMStateField[]) {
+ VMSTATE_VIRTIO_DEVICE,
+ VMSTATE_END_OF_LIST()
+ },
+};
+
+static Property virtio_audio_properties[] = {
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_audio_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
+{
+
+}
+
+static void virtio_audio_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
+{
+
+}
+
+static void virtio_audio_handle_tx_bh(VirtIODevice *vdev, VirtQueue *vq)
+{
+
+}
+
+static void virtio_audio_device_realize(DeviceState *dev, Error **errp)
+{
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ VirtIOAudio *vaudio = VIRTIO_AUDIO(dev);
+
+ virtio_init(vdev, "virtio-audio", VIRTIO_ID_AUDIO,
+ sizeof(struct virtio_audio_config));
+
+ vaudio->rx_vq = virtio_add_queue(vdev, 128, virtio_audio_handle_rx);
+ vaudio->tx_vq = virtio_add_queue(vdev, 128, virtio_audio_handle_tx_bh);
+ vaudio->ctrl_vq = virtio_add_queue(vdev, 64, virtio_audio_handle_ctrl);
+}
+
+static void virtio_audio_device_unrealize(DeviceState *dev, Error **errp)
+{
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ //VirtIOAudio *vaudio = VIRTIO_AUDIO(dev);
+
+ virtio_del_queue(vdev, 3);
+ virtio_cleanup(vdev);
+}
+
+static void virtio_audio_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+
+ dc->props = virtio_audio_properties;
+ dc->vmsd = &vmstate_virtio_audio;
+ set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
+ vdc->realize = virtio_audio_device_realize;
+ vdc->unrealize = virtio_audio_device_unrealize;
+ vdc->get_config = virtio_audio_get_config;
+ vdc->set_config = virtio_audio_set_config;
+ vdc->get_features = virtio_audio_get_features;
+ vdc->set_status = virtio_audio_set_status;
+ vdc->reset = virtio_audio_reset;
+}
+
+static void virtio_audio_instance_init(Object *obj)
+{
+ VirtIOAudio *vaudio = VIRTIO_AUDIO(obj);
+
+ /*
+ * The default config_size is sizeof(struct virtio_audio_config).
+ * Can be overriden with virtio_audio_set_config_size.
+ */
+ vaudio->config_size = sizeof(struct virtio_audio_config);
+}
+
+static const TypeInfo virtio_audio_info = {
+ .name = TYPE_VIRTIO_AUDIO,
+ .parent = TYPE_VIRTIO_DEVICE,
+ .instance_size = sizeof(VirtIOAudio),
+ .instance_init = virtio_audio_instance_init,
+ .class_init = virtio_audio_class_init,
+};
+
+static void virtio_register_types(void)
+{
+ type_register_static(&virtio_audio_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 8b0d6b69cd..adf7a2ed08 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -25,6 +25,7 @@
#include "hw/virtio/virtio-scsi.h"
#include "hw/virtio/virtio-balloon.h"
#include "hw/virtio/virtio-input.h"
+#include "hw/virtio/virtio-audio.h"
#include "hw/pci/pci.h"
#include "qapi/error.h"
#include "qemu/error-report.h"
@@ -2473,6 +2474,53 @@ static const TypeInfo virtio_rng_pci_info = {
.class_init = virtio_rng_pci_class_init,
};
+/* virtio-audio-pci */
+
+static void virtio_audio_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
+{
+ VirtIOAudioPCI *vaudio = VIRTIO_AUDIO_PCI(vpci_dev);
+ DeviceState *vdev = DEVICE(&vaudio->vdev);
+ Error *err = NULL;
+
+ qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus));
+ object_property_set_bool(OBJECT(vdev), true, "realized", &err);
+ if (err) {
+ error_propagate(errp, err);
+ return;
+ }
+}
+
+static void virtio_audio_pci_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+ PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass);
+
+ k->realize = virtio_audio_pci_realize;
+ set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
+
+ pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_AUDIO;
+ pcidev_k->revision = VIRTIO_PCI_ABI_VERSION;
+ pcidev_k->class_id = PCI_CLASS_OTHERS;
+}
+
+static void virtio_audio_initfn(Object *obj)
+{
+ VirtIOAudioPCI *dev = VIRTIO_AUDIO_PCI(obj);
+
+ virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev),
+ TYPE_VIRTIO_AUDIO);
+}
+
+static const TypeInfo virtio_audio_pci_info = {
+ .name = TYPE_VIRTIO_AUDIO_PCI,
+ .parent = TYPE_VIRTIO_PCI,
+ .instance_size = sizeof(VirtIOAudioPCI),
+ .instance_init = virtio_audio_initfn,
+ .class_init = virtio_audio_pci_class_init,
+};
+
/* virtio-input-pci */
static Property virtio_input_pci_properties[] = {
@@ -2662,6 +2710,7 @@ static void virtio_pci_register_types(void)
type_register_static(&virtio_balloon_pci_info);
type_register_static(&virtio_serial_pci_info);
type_register_static(&virtio_net_pci_info);
+ type_register_static(&virtio_audio_pci_info);
#ifdef CONFIG_VHOST_SCSI
type_register_static(&vhost_scsi_pci_info);
#endif
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index 69f5959623..9a6a51f118 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -27,6 +27,7 @@
#include "hw/virtio/virtio-gpu.h"
#include "hw/virtio/virtio-crypto.h"
#include "hw/virtio/vhost-user-scsi.h"
+#include "hw/virtio/virtio-audio.h"
#ifdef CONFIG_VIRTFS
#include "hw/9pfs/virtio-9p.h"
@@ -53,6 +54,7 @@ typedef struct VirtIOInputHostPCI VirtIOInputHostPCI;
typedef struct VirtIOGPUPCI VirtIOGPUPCI;
typedef struct VHostVSockPCI VHostVSockPCI;
typedef struct VirtIOCryptoPCI VirtIOCryptoPCI;
+typedef struct VirtIOAudioPCI VirtIOAudioPCI;
/* virtio-pci-bus */
@@ -392,6 +394,17 @@ struct VirtIOCryptoPCI {
VirtIOPCIProxy parent_obj;
VirtIOCrypto vdev;
};
+/*
+ * virtio-audio-pci: This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_AUDIO_PCI "virtio-audio-pci"
+#define VIRTIO_AUDIO_PCI(obj) \
+ OBJECT_CHECK(VirtIOAudioPCI, (obj), TYPE_VIRTIO_AUDIO_PCI)
+
+struct VirtIOAudioPCI {
+ VirtIOPCIProxy parent_obj;
+ VirtIOAudio vdev;
+};
/* Virtio ABI version, if we increment this, we break the guest driver. */
#define VIRTIO_PCI_ABI_VERSION 0
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index e598b095eb..8b701a3e73 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -81,6 +81,7 @@
#define PCI_DEVICE_ID_VIRTIO_CONSOLE 0x1003
#define PCI_DEVICE_ID_VIRTIO_SCSI 0x1004
#define PCI_DEVICE_ID_VIRTIO_RNG 0x1005
+#define PCI_DEVICE_ID_VIRTIO_AUDIO 0x1006
#define PCI_DEVICE_ID_VIRTIO_9P 0x1009
#define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012
diff --git a/include/hw/virtio/virtio-audio.h b/include/hw/virtio/virtio-audio.h
new file mode 100644
index 0000000000..420238741f
--- /dev/null
+++ b/include/hw/virtio/virtio-audio.h
@@ -0,0 +1,61 @@
+/*
+ * Virtio audio Support
+ *
+ * Copyright (c) 2017 Intel Corperation.
+ *
+ * Authors:
+ * Luo Xionghu<xionghu.luo at intel.com>
+ * Liam Girdwood <liam.r.girdwood at linux.intel.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or
+ * (at your option) any later version. See the COPYING file in the
+ * top-level directory.
+ */
+
+#ifndef _QEMU_VIRTIO_AUDIO_H
+#define _QEMU_VIRTIO_AUDIO_H
+
+#include "standard-headers/linux/virtio_audio.h"
+#include "hw/virtio/virtio.h"
+#include "sysemu/iothread.h"
+
+
+#define DEBUG_VIRTIO_AUDIO 1
+
+#define APRINTF(fmt, ...) \
+do { \
+ if (DEBUG_VIRTIO_AUDIO) { \
+ fprintf(stderr, "virtio_audio: " fmt, ##__VA_ARGS__); \
+ } \
+} while (0)
+
+
+#define TYPE_VIRTIO_AUDIO "virtio-audio-device"
+#define VIRTIO_AUDIO(obj) \
+ OBJECT_CHECK(VirtIOAudio, (obj), TYPE_VIRTIO_AUDIO)
+#define VIRTIO_AUDIO_GET_PARENT_CLASS(obj) \
+ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_AUDIO)
+
+struct virtio_audio_config {
+ uint32_t status;
+
+};
+
+typedef struct VirtIOAudio {
+ VirtIODevice parent_obj;
+
+ VirtQueue *vqs;
+ VirtQueue *rx_vq;
+ VirtQueue *tx_vq;
+ VirtQueue *ctrl_vq;
+
+ uint32_t max_queues;
+ uint32_t status;
+
+ int multiqueue;
+ uint32_t curr_queues;
+ size_t config_size;
+} VirtIOAudio;
+
+#endif /* _QEMU_VIRTIO_AUDIO_H */
+
diff --git a/include/standard-headers/linux/virtio_audio.h b/include/standard-headers/linux/virtio_audio.h
new file mode 100644
index 0000000000..2605e98684
--- /dev/null
+++ b/include/standard-headers/linux/virtio_audio.h
@@ -0,0 +1,9 @@
+#ifndef _LINUX_VIRTIO_AUDIO_H
+#define _LINUX_VIRTIO_AUDIO_H
+/* This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers. */
+#include "standard-headers/linux/virtio_ids.h"
+#include "standard-headers/linux/virtio_config.h"
+
+#endif /* _LINUX_VIRTIO_AUDIO_H */
+
diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard-headers/linux/virtio_ids.h
index 6d5c3b2d4f..197a7bb7e6 100644
--- a/include/standard-headers/linux/virtio_ids.h
+++ b/include/standard-headers/linux/virtio_ids.h
@@ -43,5 +43,6 @@
#define VIRTIO_ID_INPUT 18 /* virtio input */
#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */
#define VIRTIO_ID_CRYPTO 20 /* virtio crypto */
+#define VIRTIO_ID_AUDIO 21 /* virtio audio */
#endif /* _LINUX_VIRTIO_IDS_H */
--
2.11.0
More information about the Beignet
mailing list