Revision 6b331efb
b/hw/virtio-pci.c | ||
---|---|---|
18 | 18 |
#include "virtio.h" |
19 | 19 |
#include "virtio-blk.h" |
20 | 20 |
#include "virtio-net.h" |
21 |
#include "virtio-serial.h" |
|
21 | 22 |
#include "pci.h" |
22 | 23 |
#include "qemu-error.h" |
23 | 24 |
#include "msix.h" |
... | ... | |
109 | 110 |
#ifdef CONFIG_LINUX |
110 | 111 |
V9fsConf fsconf; |
111 | 112 |
#endif |
112 |
/* Max. number of ports we can have for a the virtio-serial device */ |
|
113 |
uint32_t max_virtserial_ports; |
|
113 |
virtio_serial_conf serial; |
|
114 | 114 |
virtio_net_conf net; |
115 | 115 |
bool ioeventfd_disabled; |
116 | 116 |
bool ioeventfd_started; |
... | ... | |
770 | 770 |
proxy->class_code != PCI_CLASS_OTHERS) /* qemu-kvm */ |
771 | 771 |
proxy->class_code = PCI_CLASS_COMMUNICATION_OTHER; |
772 | 772 |
|
773 |
vdev = virtio_serial_init(&pci_dev->qdev, proxy->max_virtserial_ports);
|
|
773 |
vdev = virtio_serial_init(&pci_dev->qdev, &proxy->serial);
|
|
774 | 774 |
if (!vdev) { |
775 | 775 |
return -1; |
776 | 776 |
} |
777 | 777 |
vdev->nvectors = proxy->nvectors == DEV_NVECTORS_UNSPECIFIED |
778 |
? proxy->max_virtserial_ports + 1 |
|
778 |
? proxy->serial.max_virtserial_ports + 1
|
|
779 | 779 |
: proxy->nvectors; |
780 | 780 |
virtio_init_pci(proxy, vdev, |
781 | 781 |
PCI_VENDOR_ID_REDHAT_QUMRANET, |
... | ... | |
902 | 902 |
DEV_NVECTORS_UNSPECIFIED), |
903 | 903 |
DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0), |
904 | 904 |
DEFINE_VIRTIO_COMMON_FEATURES(VirtIOPCIProxy, host_features), |
905 |
DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, max_virtserial_ports,
|
|
906 |
31), |
|
905 |
DEFINE_PROP_UINT32("max_ports", VirtIOPCIProxy, |
|
906 |
serial.max_virtserial_ports, 31),
|
|
907 | 907 |
DEFINE_PROP_END_OF_LIST(), |
908 | 908 |
}, |
909 | 909 |
.qdev.reset = virtio_pci_reset, |
b/hw/virtio-serial-bus.c | ||
---|---|---|
811 | 811 |
qdev_register(&info->qdev); |
812 | 812 |
} |
813 | 813 |
|
814 |
VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports)
|
|
814 |
VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
|
|
815 | 815 |
{ |
816 | 816 |
VirtIOSerial *vser; |
817 | 817 |
VirtIODevice *vdev; |
818 | 818 |
uint32_t i, max_supported_ports; |
819 | 819 |
|
820 |
if (!max_nr_ports)
|
|
820 |
if (!conf->max_virtserial_ports)
|
|
821 | 821 |
return NULL; |
822 | 822 |
|
823 | 823 |
/* Each port takes 2 queues, and one pair is for the control queue */ |
824 | 824 |
max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1; |
825 | 825 |
|
826 |
if (max_nr_ports > max_supported_ports) {
|
|
826 |
if (conf->max_virtserial_ports > max_supported_ports) {
|
|
827 | 827 |
error_report("maximum ports supported: %u", max_supported_ports); |
828 | 828 |
return NULL; |
829 | 829 |
} |
... | ... | |
839 | 839 |
vser->bus->vser = vser; |
840 | 840 |
QTAILQ_INIT(&vser->ports); |
841 | 841 |
|
842 |
vser->bus->max_nr_ports = max_nr_ports;
|
|
843 |
vser->ivqs = qemu_malloc(max_nr_ports * sizeof(VirtQueue *));
|
|
844 |
vser->ovqs = qemu_malloc(max_nr_ports * sizeof(VirtQueue *));
|
|
842 |
vser->bus->max_nr_ports = conf->max_virtserial_ports;
|
|
843 |
vser->ivqs = qemu_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
|
|
844 |
vser->ovqs = qemu_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
|
|
845 | 845 |
|
846 | 846 |
/* Add a queue for host to guest transfers for port 0 (backward compat) */ |
847 | 847 |
vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input); |
... | ... | |
866 | 866 |
vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output); |
867 | 867 |
} |
868 | 868 |
|
869 |
vser->config.max_nr_ports = max_nr_ports;
|
|
870 |
vser->ports_map = qemu_mallocz(((max_nr_ports + 31) / 32)
|
|
869 |
vser->config.max_nr_ports = conf->max_virtserial_ports;
|
|
870 |
vser->ports_map = qemu_mallocz(((conf->max_virtserial_ports + 31) / 32)
|
|
871 | 871 |
* sizeof(vser->ports_map[0])); |
872 | 872 |
/* |
873 | 873 |
* Reserve location 0 for a console port for backward compat |
b/hw/virtio-serial.h | ||
---|---|---|
45 | 45 |
uint16_t value; /* Extra information for the key */ |
46 | 46 |
}; |
47 | 47 |
|
48 |
struct virtio_serial_conf { |
|
49 |
/* Max. number of ports we can have for a virtio-serial device */ |
|
50 |
uint32_t max_virtserial_ports; |
|
51 |
}; |
|
52 |
|
|
48 | 53 |
/* Some events for the internal messages (control packets) */ |
49 | 54 |
#define VIRTIO_CONSOLE_DEVICE_READY 0 |
50 | 55 |
#define VIRTIO_CONSOLE_PORT_ADD 1 |
b/hw/virtio.h | ||
---|---|---|
195 | 195 |
struct virtio_net_conf; |
196 | 196 |
VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf, |
197 | 197 |
struct virtio_net_conf *net); |
198 |
VirtIODevice *virtio_serial_init(DeviceState *dev, uint32_t max_nr_ports); |
|
198 |
typedef struct virtio_serial_conf virtio_serial_conf; |
|
199 |
VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *serial); |
|
199 | 200 |
VirtIODevice *virtio_balloon_init(DeviceState *dev); |
200 | 201 |
#ifdef CONFIG_LINUX |
201 | 202 |
VirtIODevice *virtio_9p_init(DeviceState *dev, V9fsConf *conf); |
Also available in: Unified diff