xref: /qemu/hw/virtio/virtio-qmp.c (revision 1f5f49056d0f140568805d66f33396ed5cd90369)
128b629abSPhilippe Mathieu-Daudé /*
228b629abSPhilippe Mathieu-Daudé  * Virtio QMP helpers
328b629abSPhilippe Mathieu-Daudé  *
428b629abSPhilippe Mathieu-Daudé  * Copyright IBM, Corp. 2007
528b629abSPhilippe Mathieu-Daudé  *
628b629abSPhilippe Mathieu-Daudé  * Authors:
728b629abSPhilippe Mathieu-Daudé  *  Anthony Liguori   <aliguori@us.ibm.com>
828b629abSPhilippe Mathieu-Daudé  *
928b629abSPhilippe Mathieu-Daudé  * SPDX-License-Identifier: GPL-2.0-or-later
1028b629abSPhilippe Mathieu-Daudé  */
1128b629abSPhilippe Mathieu-Daudé 
1228b629abSPhilippe Mathieu-Daudé #include "qemu/osdep.h"
1328b629abSPhilippe Mathieu-Daudé #include "virtio-qmp.h"
1428b629abSPhilippe Mathieu-Daudé 
159d94c213SPhilippe Mathieu-Daudé #include "qapi/error.h"
169d94c213SPhilippe Mathieu-Daudé #include "qapi/qapi-commands-virtio.h"
179d94c213SPhilippe Mathieu-Daudé #include "qapi/qapi-commands-qom.h"
189d94c213SPhilippe Mathieu-Daudé #include "qapi/qmp/qobject.h"
199d94c213SPhilippe Mathieu-Daudé #include "qapi/qmp/qjson.h"
203d123a8bSJonah Palmer #include "hw/virtio/vhost-user.h"
219d94c213SPhilippe Mathieu-Daudé 
2228b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_ids.h"
2328b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/vhost_types.h"
2428b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_blk.h"
2528b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_console.h"
2628b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_gpu.h"
2728b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_net.h"
2828b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_scsi.h"
2928b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_i2c.h"
3028b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_balloon.h"
3128b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_iommu.h"
3228b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_mem.h"
3328b629abSPhilippe Mathieu-Daudé #include "standard-headers/linux/virtio_vsock.h"
3458f81689SJonah Palmer #include "standard-headers/linux/virtio_gpio.h"
3528b629abSPhilippe Mathieu-Daudé 
3628b629abSPhilippe Mathieu-Daudé #include CONFIG_DEVICES
3728b629abSPhilippe Mathieu-Daudé 
3828b629abSPhilippe Mathieu-Daudé #define FEATURE_ENTRY(name, desc) (qmp_virtio_feature_map_t) \
3928b629abSPhilippe Mathieu-Daudé     { .virtio_bit = name, .feature_desc = desc }
4028b629abSPhilippe Mathieu-Daudé 
4128b629abSPhilippe Mathieu-Daudé /* Virtio transport features mapping */
4228b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_transport_map[] = {
4328b629abSPhilippe Mathieu-Daudé     /* Virtio device transport features */
4428b629abSPhilippe Mathieu-Daudé #ifndef VIRTIO_CONFIG_NO_LEGACY
4528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_NOTIFY_ON_EMPTY, \
4628b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. "
4728b629abSPhilippe Mathieu-Daudé             "descs. on VQ"),
4828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_ANY_LAYOUT, \
4928b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts"),
5028b629abSPhilippe Mathieu-Daudé #endif /* !VIRTIO_CONFIG_NO_LEGACY */
5128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_VERSION_1, \
5228b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"),
5328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_IOMMU_PLATFORM, \
5428b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_IOMMU_PLATFORM: Device can be used on IOMMU platform"),
5528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_RING_PACKED, \
5628b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_RING_PACKED: Device supports packed VQ layout"),
5728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_IN_ORDER, \
5828b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_IN_ORDER: Device uses buffers in same order as made "
5928b629abSPhilippe Mathieu-Daudé             "available by driver"),
6028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_ORDER_PLATFORM, \
6128b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_ORDER_PLATFORM: Memory accesses ordered by platform"),
6228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_F_SR_IOV, \
6328b629abSPhilippe Mathieu-Daudé             "VIRTIO_F_SR_IOV: Device supports single root I/O virtualization"),
6492f04221SDavid Edmondson     FEATURE_ENTRY(VIRTIO_F_RING_RESET, \
6592f04221SDavid Edmondson             "VIRTIO_F_RING_RESET: Driver can reset a queue individually"),
6628b629abSPhilippe Mathieu-Daudé     /* Virtio ring transport features */
6728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_RING_F_INDIRECT_DESC, \
6828b629abSPhilippe Mathieu-Daudé             "VIRTIO_RING_F_INDIRECT_DESC: Indirect descriptors supported"),
6928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_RING_F_EVENT_IDX, \
7028b629abSPhilippe Mathieu-Daudé             "VIRTIO_RING_F_EVENT_IDX: Used & avail. event fields enabled"),
7128b629abSPhilippe Mathieu-Daudé     { -1, "" }
7228b629abSPhilippe Mathieu-Daudé };
7328b629abSPhilippe Mathieu-Daudé 
7428b629abSPhilippe Mathieu-Daudé /* Vhost-user protocol features mapping */
7528b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t vhost_user_protocol_map[] = {
7628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_MQ, \
7728b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_MQ: Multiqueue protocol supported"),
7828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_LOG_SHMFD, \
7928b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_LOG_SHMFD: Shared log memory fd supported"),
8028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_RARP, \
8128b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_RARP: Vhost-user back-end RARP broadcasting "
8228b629abSPhilippe Mathieu-Daudé             "supported"),
8328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_REPLY_ACK, \
8428b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_REPLY_ACK: Requested operation status ack. "
8528b629abSPhilippe Mathieu-Daudé             "supported"),
8628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_NET_MTU, \
8728b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_NET_MTU: Expose host MTU to guest supported"),
88a84ec993SMaxime Coquelin     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_BACKEND_REQ, \
89a84ec993SMaxime Coquelin             "VHOST_USER_PROTOCOL_F_BACKEND_REQ: Socket fd for back-end initiated "
9028b629abSPhilippe Mathieu-Daudé             "requests supported"),
9128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CROSS_ENDIAN, \
9228b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_CROSS_ENDIAN: Endianness of VQs for legacy "
9328b629abSPhilippe Mathieu-Daudé             "devices supported"),
9428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CRYPTO_SESSION, \
9528b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_CRYPTO_SESSION: Session creation for crypto "
9628b629abSPhilippe Mathieu-Daudé             "operations supported"),
9728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_PAGEFAULT, \
9828b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_PAGEFAULT: Request servicing on userfaultfd "
9928b629abSPhilippe Mathieu-Daudé             "for accessed pages supported"),
10028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CONFIG, \
10128b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_CONFIG: Vhost-user messaging for virtio "
10228b629abSPhilippe Mathieu-Daudé             "device configuration space supported"),
103a84ec993SMaxime Coquelin     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD, \
104f8ed3648SManos Pitsidianakis             "VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD: Backend fd communication "
10528b629abSPhilippe Mathieu-Daudé             "channel supported"),
10628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_HOST_NOTIFIER, \
10728b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_HOST_NOTIFIER: Host notifiers for specified "
10828b629abSPhilippe Mathieu-Daudé             "VQs supported"),
10928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD, \
11028b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD: Shared inflight I/O buffers "
11128b629abSPhilippe Mathieu-Daudé             "supported"),
11228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_RESET_DEVICE, \
11328b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_RESET_DEVICE: Disabling all rings and "
11428b629abSPhilippe Mathieu-Daudé             "resetting internal device state supported"),
11528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS, \
11628b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS: In-band messaging "
11728b629abSPhilippe Mathieu-Daudé             "supported"),
11828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS, \
11928b629abSPhilippe Mathieu-Daudé             "VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS: Configuration for "
12028b629abSPhilippe Mathieu-Daudé             "memory slots supported"),
12158f81689SJonah Palmer     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_STATUS, \
12258f81689SJonah Palmer             "VHOST_USER_PROTOCOL_F_STATUS: Querying and notifying back-end "
12358f81689SJonah Palmer             "device status supported"),
12428b629abSPhilippe Mathieu-Daudé     { -1, "" }
12528b629abSPhilippe Mathieu-Daudé };
12628b629abSPhilippe Mathieu-Daudé 
12728b629abSPhilippe Mathieu-Daudé /* virtio device configuration statuses */
12828b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_config_status_map[] = {
12928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_DRIVER_OK, \
13028b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"),
13128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_FEATURES_OK, \
13228b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete"),
13328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_DRIVER, \
13428b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device"),
13528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_NEEDS_RESET, \
13628b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_NEEDS_RESET: Irrecoverable error, device needs "
13728b629abSPhilippe Mathieu-Daudé             "reset"),
13828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_FAILED, \
13928b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_FAILED: Error in guest, device failed"),
14028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_ACKNOWLEDGE, \
14128b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found"),
14228b629abSPhilippe Mathieu-Daudé     { -1, "" }
14328b629abSPhilippe Mathieu-Daudé };
14428b629abSPhilippe Mathieu-Daudé 
14528b629abSPhilippe Mathieu-Daudé /* virtio-blk features mapping */
14628b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BLK
14728b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
14828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_SIZE_MAX, \
14928b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_SIZE_MAX: Max segment size is size_max"),
15028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_SEG_MAX, \
15128b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_SEG_MAX: Max segments in a request is seg_max"),
15228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_GEOMETRY, \
15328b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_GEOMETRY: Legacy geometry available"),
15428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_RO, \
15528b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_RO: Device is read-only"),
15628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_BLK_SIZE, \
15728b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_BLK_SIZE: Block size of disk available"),
15828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_TOPOLOGY, \
15928b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_TOPOLOGY: Topology information available"),
16028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_MQ, \
16128b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_MQ: Multiqueue supported"),
16228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_DISCARD, \
16328b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_DISCARD: Discard command supported"),
16428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_WRITE_ZEROES, \
16528b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_WRITE_ZEROES: Write zeroes command supported"),
16658f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_BLK_F_SECURE_ERASE, \
16758f81689SJonah Palmer             "VIRTIO_BLK_F_SECURE_ERASE: Secure erase supported"),
1684f736650SSam Li     FEATURE_ENTRY(VIRTIO_BLK_F_ZONED, \
1694f736650SSam Li             "VIRTIO_BLK_F_ZONED: Zoned block devices"),
17028b629abSPhilippe Mathieu-Daudé #ifndef VIRTIO_BLK_NO_LEGACY
17128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_BARRIER, \
17228b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_BARRIER: Request barriers supported"),
17328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_SCSI, \
17428b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_SCSI: SCSI packet commands supported"),
17528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_FLUSH, \
17628b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_FLUSH: Flush command supported"),
17728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_CONFIG_WCE, \
17828b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_CONFIG_WCE: Cache writeback and writethrough modes "
17928b629abSPhilippe Mathieu-Daudé             "supported"),
18028b629abSPhilippe Mathieu-Daudé #endif /* !VIRTIO_BLK_NO_LEGACY */
18128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
18228b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
18328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
18428b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
18528b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
18628b629abSPhilippe Mathieu-Daudé     { -1, "" }
18728b629abSPhilippe Mathieu-Daudé };
18828b629abSPhilippe Mathieu-Daudé #endif
18928b629abSPhilippe Mathieu-Daudé 
19028b629abSPhilippe Mathieu-Daudé /* virtio-serial features mapping */
19128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SERIAL
19228b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_serial_feature_map[] = {
19328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONSOLE_F_SIZE, \
19428b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONSOLE_F_SIZE: Host providing console size"),
19528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONSOLE_F_MULTIPORT, \
19628b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported"),
19728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONSOLE_F_EMERG_WRITE, \
19828b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported"),
19928b629abSPhilippe Mathieu-Daudé     { -1, "" }
20028b629abSPhilippe Mathieu-Daudé };
20128b629abSPhilippe Mathieu-Daudé #endif
20228b629abSPhilippe Mathieu-Daudé 
20328b629abSPhilippe Mathieu-Daudé /* virtio-gpu features mapping */
20428b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_GPU
20528b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {
20628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_VIRGL, \
20728b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_VIRGL: Virgl 3D mode supported"),
20828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_EDID, \
20928b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_EDID: EDID metadata supported"),
21028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_RESOURCE_UUID, \
21128b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_RESOURCE_UUID: Resource UUID assigning supported"),
21228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_RESOURCE_BLOB, \
21328b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_RESOURCE_BLOB: Size-based blob resources supported"),
21428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_CONTEXT_INIT, \
21528b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_CONTEXT_INIT: Context types and synchronization "
21628b629abSPhilippe Mathieu-Daudé             "timelines supported"),
21728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
21828b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
21928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
22028b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
22128b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
22228b629abSPhilippe Mathieu-Daudé     { -1, "" }
22328b629abSPhilippe Mathieu-Daudé };
22428b629abSPhilippe Mathieu-Daudé #endif
22528b629abSPhilippe Mathieu-Daudé 
22628b629abSPhilippe Mathieu-Daudé /* virtio-input features mapping */
22728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_INPUT
22828b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_input_feature_map[] = {
22928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
23028b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
23128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
23228b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
23328b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
23428b629abSPhilippe Mathieu-Daudé     { -1, "" }
23528b629abSPhilippe Mathieu-Daudé };
23628b629abSPhilippe Mathieu-Daudé #endif
23728b629abSPhilippe Mathieu-Daudé 
23828b629abSPhilippe Mathieu-Daudé /* virtio-net features mapping */
23928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_NET
24028b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_net_feature_map[] = {
24128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CSUM, \
24228b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum "
24328b629abSPhilippe Mathieu-Daudé             "supported"),
24428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_CSUM, \
24528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial "
24628b629abSPhilippe Mathieu-Daudé             "checksum supported"),
24728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \
24828b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading "
24928b629abSPhilippe Mathieu-Daudé             "reconfig. supported"),
25028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MTU, \
25128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MTU: Device max MTU reporting supported"),
25228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MAC, \
25328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MAC: Device has given MAC address"),
25428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_TSO4, \
25528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4"),
25628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_TSO6, \
25728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6"),
25828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_ECN, \
25928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN"),
26028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_UFO, \
26128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO"),
26228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_TSO4, \
26328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4"),
26428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_TSO6, \
26528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6"),
26628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_ECN, \
26728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN"),
26828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_UFO, \
26928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_UFO: Device can receive UFO"),
27028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MRG_RXBUF, \
27128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"),
27228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_STATUS, \
27328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_STATUS: Configuration status field available"),
27428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_VQ, \
27528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_VQ: Control channel available"),
27628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_RX, \
27728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported"),
27828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_VLAN, \
27928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported"),
28028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_RX_EXTRA, \
28128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported"),
28228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_ANNOUNCE, \
28328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets "
28428b629abSPhilippe Mathieu-Daudé             "supported"),
28528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MQ, \
28628b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MQ: Multiqueue with automatic receive steering "
28728b629abSPhilippe Mathieu-Daudé             "supported"),
28828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_MAC_ADDR, \
28928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control "
29028b629abSPhilippe Mathieu-Daudé             "channel"),
29158f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_NOTF_COAL, \
29258f81689SJonah Palmer             "VIRTIO_NET_F_NOTF_COAL: Device supports coalescing notifications"),
29358f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_USO4, \
29458f81689SJonah Palmer             "VIRTIO_NET_F_GUEST_USO4: Driver can receive USOv4"),
29558f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_USO6, \
29658f81689SJonah Palmer             "VIRTIO_NET_F_GUEST_USO4: Driver can receive USOv6"),
29758f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_HOST_USO, \
29858f81689SJonah Palmer             "VIRTIO_NET_F_HOST_USO: Device can receive USO"),
29928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HASH_REPORT, \
30028b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HASH_REPORT: Hash reporting supported"),
30128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_RSS, \
30228b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_RSS: RSS RX steering supported"),
30328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_RSC_EXT, \
30428b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_RSC_EXT: Extended coalescing info supported"),
30528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_STANDBY, \
30628b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_STANDBY: Device acting as standby for primary "
30728b629abSPhilippe Mathieu-Daudé             "device with same MAC addr. supported"),
30828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_SPEED_DUPLEX, \
30928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_SPEED_DUPLEX: Device set linkspeed and duplex"),
31028b629abSPhilippe Mathieu-Daudé #ifndef VIRTIO_NET_NO_LEGACY
31128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GSO, \
31228b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GSO: Handling GSO-type packets supported"),
31328b629abSPhilippe Mathieu-Daudé #endif /* !VIRTIO_NET_NO_LEGACY */
31428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_NET_F_VIRTIO_NET_HDR, \
31528b629abSPhilippe Mathieu-Daudé             "VHOST_NET_F_VIRTIO_NET_HDR: Virtio-net headers for RX and TX "
31628b629abSPhilippe Mathieu-Daudé             "packets supported"),
31728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
31828b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
31928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
32028b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
32128b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
32228b629abSPhilippe Mathieu-Daudé     { -1, "" }
32328b629abSPhilippe Mathieu-Daudé };
32428b629abSPhilippe Mathieu-Daudé #endif
32528b629abSPhilippe Mathieu-Daudé 
32628b629abSPhilippe Mathieu-Daudé /* virtio-scsi features mapping */
32728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SCSI
32828b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_scsi_feature_map[] = {
32928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_INOUT, \
33028b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_INOUT: Requests including read and writable data "
33146e75a77SMichael Tokarev             "buffers supported"),
33228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_HOTPLUG, \
33328b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_HOTPLUG: Reporting and handling hot-plug events "
33428b629abSPhilippe Mathieu-Daudé             "supported"),
33528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_CHANGE, \
33628b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_CHANGE: Reporting and handling LUN changes "
33728b629abSPhilippe Mathieu-Daudé             "supported"),
33828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_T10_PI, \
33928b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_T10_PI: T10 info included in request header"),
34028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
34128b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
34228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
34328b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
34428b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
34528b629abSPhilippe Mathieu-Daudé     { -1, "" }
34628b629abSPhilippe Mathieu-Daudé };
34728b629abSPhilippe Mathieu-Daudé #endif
34828b629abSPhilippe Mathieu-Daudé 
34928b629abSPhilippe Mathieu-Daudé /* virtio/vhost-user-fs features mapping */
35028b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_USER_FS
35128b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_fs_feature_map[] = {
35228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
35328b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
35428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
35528b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
35628b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
35728b629abSPhilippe Mathieu-Daudé     { -1, "" }
35828b629abSPhilippe Mathieu-Daudé };
35928b629abSPhilippe Mathieu-Daudé #endif
36028b629abSPhilippe Mathieu-Daudé 
36128b629abSPhilippe Mathieu-Daudé /* virtio/vhost-user-i2c features mapping */
36228b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_I2C_ADAPTER
36328b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_i2c_feature_map[] = {
36428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, \
36528b629abSPhilippe Mathieu-Daudé             "VIRTIO_I2C_F_ZERO_LEGNTH_REQUEST: Zero length requests supported"),
36628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
36728b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
36828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
36928b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
37028b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
37128b629abSPhilippe Mathieu-Daudé     { -1, "" }
37228b629abSPhilippe Mathieu-Daudé };
37328b629abSPhilippe Mathieu-Daudé #endif
37428b629abSPhilippe Mathieu-Daudé 
37528b629abSPhilippe Mathieu-Daudé /* virtio/vhost-vsock features mapping */
37628b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_VSOCK
37728b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_vsock_feature_map[] = {
37828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_VSOCK_F_SEQPACKET, \
37928b629abSPhilippe Mathieu-Daudé             "VIRTIO_VSOCK_F_SEQPACKET: SOCK_SEQPACKET supported"),
38028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
38128b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
38228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
38328b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
38428b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
38528b629abSPhilippe Mathieu-Daudé     { -1, "" }
38628b629abSPhilippe Mathieu-Daudé };
38728b629abSPhilippe Mathieu-Daudé #endif
38828b629abSPhilippe Mathieu-Daudé 
38928b629abSPhilippe Mathieu-Daudé /* virtio-balloon features mapping */
39028b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BALLOON
39128b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_balloon_feature_map[] = {
39228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_MUST_TELL_HOST, \
39328b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_MUST_TELL_HOST: Tell host before reclaiming "
39428b629abSPhilippe Mathieu-Daudé             "pages"),
39528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_STATS_VQ, \
39628b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_STATS_VQ: Guest memory stats VQ available"),
39728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_DEFLATE_ON_OOM, \
39828b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_DEFLATE_ON_OOM: Deflate balloon when guest OOM"),
39928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_FREE_PAGE_HINT, \
40028b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_FREE_PAGE_HINT: VQ reporting free pages enabled"),
40128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_PAGE_POISON, \
40228b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_PAGE_POISON: Guest page poisoning enabled"),
40328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_REPORTING, \
40428b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_REPORTING: Page reporting VQ enabled"),
40528b629abSPhilippe Mathieu-Daudé     { -1, "" }
40628b629abSPhilippe Mathieu-Daudé };
40728b629abSPhilippe Mathieu-Daudé #endif
40828b629abSPhilippe Mathieu-Daudé 
40928b629abSPhilippe Mathieu-Daudé /* virtio-crypto features mapping */
41028b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_CRYPTO
41128b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_crypto_feature_map[] = {
41228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
41328b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
41428b629abSPhilippe Mathieu-Daudé     { -1, "" }
41528b629abSPhilippe Mathieu-Daudé };
41628b629abSPhilippe Mathieu-Daudé #endif
41728b629abSPhilippe Mathieu-Daudé 
41828b629abSPhilippe Mathieu-Daudé /* virtio-iommu features mapping */
41928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_IOMMU
42028b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_iommu_feature_map[] = {
42128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_INPUT_RANGE, \
42228b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_INPUT_RANGE: Range of available virtual addrs. "
42328b629abSPhilippe Mathieu-Daudé             "available"),
42428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_DOMAIN_RANGE, \
42528b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_DOMAIN_RANGE: Number of supported domains "
42628b629abSPhilippe Mathieu-Daudé             "available"),
42728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_MAP_UNMAP, \
42828b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_MAP_UNMAP: Map and unmap requests available"),
42928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_BYPASS, \
43028b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_BYPASS: Endpoints not attached to domains are in "
43128b629abSPhilippe Mathieu-Daudé             "bypass mode"),
43228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_PROBE, \
43328b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_PROBE: Probe requests available"),
43428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_MMIO, \
43528b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_MMIO: VIRTIO_IOMMU_MAP_F_MMIO flag available"),
43628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_BYPASS_CONFIG, \
43728b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_BYPASS_CONFIG: Bypass field of IOMMU config "
43828b629abSPhilippe Mathieu-Daudé             "available"),
43928b629abSPhilippe Mathieu-Daudé     { -1, "" }
44028b629abSPhilippe Mathieu-Daudé };
44128b629abSPhilippe Mathieu-Daudé #endif
44228b629abSPhilippe Mathieu-Daudé 
44328b629abSPhilippe Mathieu-Daudé /* virtio-mem features mapping */
44428b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_MEM
44528b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = {
44628b629abSPhilippe Mathieu-Daudé #ifndef CONFIG_ACPI
44728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_MEM_F_ACPI_PXM, \
44828b629abSPhilippe Mathieu-Daudé             "VIRTIO_MEM_F_ACPI_PXM: node_id is an ACPI PXM and is valid"),
44928b629abSPhilippe Mathieu-Daudé #endif /* !CONFIG_ACPI */
45028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, \
45128b629abSPhilippe Mathieu-Daudé             "VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot be "
45228b629abSPhilippe Mathieu-Daudé             "accessed"),
453*1f5f4905SJuraj Marcin     FEATURE_ENTRY(VIRTIO_MEM_F_PERSISTENT_SUSPEND, \
454*1f5f4905SJuraj Marcin             "VIRTIO_MEM_F_PERSISTENT_SUSPND: Plugged memory will remain "
455*1f5f4905SJuraj Marcin             "plugged when suspending+resuming"),
45628b629abSPhilippe Mathieu-Daudé     { -1, "" }
45728b629abSPhilippe Mathieu-Daudé };
45828b629abSPhilippe Mathieu-Daudé #endif
45928b629abSPhilippe Mathieu-Daudé 
46028b629abSPhilippe Mathieu-Daudé /* virtio-rng features mapping */
46128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_RNG
46228b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_rng_feature_map[] = {
46328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
46428b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
46528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
46628b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
46728b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
46828b629abSPhilippe Mathieu-Daudé     { -1, "" }
46928b629abSPhilippe Mathieu-Daudé };
47028b629abSPhilippe Mathieu-Daudé #endif
47128b629abSPhilippe Mathieu-Daudé 
47258f81689SJonah Palmer /* virtio/vhost-gpio features mapping */
47358f81689SJonah Palmer #ifdef CONFIG_VHOST_USER_GPIO
47458f81689SJonah Palmer static const qmp_virtio_feature_map_t virtio_gpio_feature_map[] = {
47558f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_GPIO_F_IRQ, \
47658f81689SJonah Palmer             "VIRTIO_GPIO_F_IRQ: Device supports interrupts on GPIO lines"),
47758f81689SJonah Palmer     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
47858f81689SJonah Palmer             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
47958f81689SJonah Palmer             "negotiation supported"),
48058f81689SJonah Palmer     { -1, "" }
48158f81689SJonah Palmer };
48258f81689SJonah Palmer #endif
48358f81689SJonah Palmer 
48428b629abSPhilippe Mathieu-Daudé #define CONVERT_FEATURES(type, map, is_status, bitmap)   \
48528b629abSPhilippe Mathieu-Daudé     ({                                                   \
48628b629abSPhilippe Mathieu-Daudé         type *list = NULL;                               \
48728b629abSPhilippe Mathieu-Daudé         type *node;                                      \
48828b629abSPhilippe Mathieu-Daudé         for (i = 0; map[i].virtio_bit != -1; i++) {      \
48928b629abSPhilippe Mathieu-Daudé             if (is_status) {                             \
49028b629abSPhilippe Mathieu-Daudé                 bit = map[i].virtio_bit;                 \
49128b629abSPhilippe Mathieu-Daudé             }                                            \
49228b629abSPhilippe Mathieu-Daudé             else {                                       \
49328b629abSPhilippe Mathieu-Daudé                 bit = 1ULL << map[i].virtio_bit;         \
49428b629abSPhilippe Mathieu-Daudé             }                                            \
49528b629abSPhilippe Mathieu-Daudé             if ((bitmap & bit) == 0) {                   \
49628b629abSPhilippe Mathieu-Daudé                 continue;                                \
49728b629abSPhilippe Mathieu-Daudé             }                                            \
49828b629abSPhilippe Mathieu-Daudé             node = g_new0(type, 1);                      \
49928b629abSPhilippe Mathieu-Daudé             node->value = g_strdup(map[i].feature_desc); \
50028b629abSPhilippe Mathieu-Daudé             node->next = list;                           \
50128b629abSPhilippe Mathieu-Daudé             list = node;                                 \
50228b629abSPhilippe Mathieu-Daudé             bitmap ^= bit;                               \
50328b629abSPhilippe Mathieu-Daudé         }                                                \
50428b629abSPhilippe Mathieu-Daudé         list;                                            \
50528b629abSPhilippe Mathieu-Daudé     })
50628b629abSPhilippe Mathieu-Daudé 
50728b629abSPhilippe Mathieu-Daudé VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap)
50828b629abSPhilippe Mathieu-Daudé {
50928b629abSPhilippe Mathieu-Daudé     VirtioDeviceStatus *status;
51028b629abSPhilippe Mathieu-Daudé     uint8_t bit;
51128b629abSPhilippe Mathieu-Daudé     int i;
51228b629abSPhilippe Mathieu-Daudé 
51328b629abSPhilippe Mathieu-Daudé     status = g_new0(VirtioDeviceStatus, 1);
51428b629abSPhilippe Mathieu-Daudé     status->statuses = CONVERT_FEATURES(strList, virtio_config_status_map,
51528b629abSPhilippe Mathieu-Daudé                                         1, bitmap);
51628b629abSPhilippe Mathieu-Daudé     status->has_unknown_statuses = bitmap != 0;
51728b629abSPhilippe Mathieu-Daudé     if (status->has_unknown_statuses) {
51828b629abSPhilippe Mathieu-Daudé         status->unknown_statuses = bitmap;
51928b629abSPhilippe Mathieu-Daudé     }
52028b629abSPhilippe Mathieu-Daudé 
52128b629abSPhilippe Mathieu-Daudé     return status;
52228b629abSPhilippe Mathieu-Daudé }
52328b629abSPhilippe Mathieu-Daudé 
52428b629abSPhilippe Mathieu-Daudé VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap)
52528b629abSPhilippe Mathieu-Daudé {
52628b629abSPhilippe Mathieu-Daudé     VhostDeviceProtocols *vhu_protocols;
52728b629abSPhilippe Mathieu-Daudé     uint64_t bit;
52828b629abSPhilippe Mathieu-Daudé     int i;
52928b629abSPhilippe Mathieu-Daudé 
53028b629abSPhilippe Mathieu-Daudé     vhu_protocols = g_new0(VhostDeviceProtocols, 1);
53128b629abSPhilippe Mathieu-Daudé     vhu_protocols->protocols =
53228b629abSPhilippe Mathieu-Daudé                     CONVERT_FEATURES(strList,
53328b629abSPhilippe Mathieu-Daudé                                      vhost_user_protocol_map, 0, bitmap);
53428b629abSPhilippe Mathieu-Daudé     vhu_protocols->has_unknown_protocols = bitmap != 0;
53528b629abSPhilippe Mathieu-Daudé     if (vhu_protocols->has_unknown_protocols) {
53628b629abSPhilippe Mathieu-Daudé         vhu_protocols->unknown_protocols = bitmap;
53728b629abSPhilippe Mathieu-Daudé     }
53828b629abSPhilippe Mathieu-Daudé 
53928b629abSPhilippe Mathieu-Daudé     return vhu_protocols;
54028b629abSPhilippe Mathieu-Daudé }
54128b629abSPhilippe Mathieu-Daudé 
54228b629abSPhilippe Mathieu-Daudé VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, uint64_t bitmap)
54328b629abSPhilippe Mathieu-Daudé {
54428b629abSPhilippe Mathieu-Daudé     VirtioDeviceFeatures *features;
54528b629abSPhilippe Mathieu-Daudé     uint64_t bit;
54628b629abSPhilippe Mathieu-Daudé     int i;
54728b629abSPhilippe Mathieu-Daudé 
54828b629abSPhilippe Mathieu-Daudé     features = g_new0(VirtioDeviceFeatures, 1);
54928b629abSPhilippe Mathieu-Daudé     features->has_dev_features = true;
55028b629abSPhilippe Mathieu-Daudé 
55128b629abSPhilippe Mathieu-Daudé     /* transport features */
55228b629abSPhilippe Mathieu-Daudé     features->transports = CONVERT_FEATURES(strList, virtio_transport_map, 0,
55328b629abSPhilippe Mathieu-Daudé                                             bitmap);
55428b629abSPhilippe Mathieu-Daudé 
55528b629abSPhilippe Mathieu-Daudé     /* device features */
55628b629abSPhilippe Mathieu-Daudé     switch (device_id) {
55728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SERIAL
55828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CONSOLE:
55928b629abSPhilippe Mathieu-Daudé         features->dev_features =
56028b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_serial_feature_map, 0, bitmap);
56128b629abSPhilippe Mathieu-Daudé         break;
56228b629abSPhilippe Mathieu-Daudé #endif
56328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BLK
56428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_BLOCK:
56528b629abSPhilippe Mathieu-Daudé         features->dev_features =
56628b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_blk_feature_map, 0, bitmap);
56728b629abSPhilippe Mathieu-Daudé         break;
56828b629abSPhilippe Mathieu-Daudé #endif
56928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_GPU
57028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_GPU:
57128b629abSPhilippe Mathieu-Daudé         features->dev_features =
57228b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_gpu_feature_map, 0, bitmap);
57328b629abSPhilippe Mathieu-Daudé         break;
57428b629abSPhilippe Mathieu-Daudé #endif
57528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_NET
57628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_NET:
57728b629abSPhilippe Mathieu-Daudé         features->dev_features =
57828b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_net_feature_map, 0, bitmap);
57928b629abSPhilippe Mathieu-Daudé         break;
58028b629abSPhilippe Mathieu-Daudé #endif
58128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SCSI
58228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SCSI:
58328b629abSPhilippe Mathieu-Daudé         features->dev_features =
58428b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_scsi_feature_map, 0, bitmap);
58528b629abSPhilippe Mathieu-Daudé         break;
58628b629abSPhilippe Mathieu-Daudé #endif
58728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BALLOON
58828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_BALLOON:
58928b629abSPhilippe Mathieu-Daudé         features->dev_features =
59028b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_balloon_feature_map, 0, bitmap);
59128b629abSPhilippe Mathieu-Daudé         break;
59228b629abSPhilippe Mathieu-Daudé #endif
59328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_IOMMU
59428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_IOMMU:
59528b629abSPhilippe Mathieu-Daudé         features->dev_features =
59628b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_iommu_feature_map, 0, bitmap);
59728b629abSPhilippe Mathieu-Daudé         break;
59828b629abSPhilippe Mathieu-Daudé #endif
59928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_INPUT
60028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_INPUT:
60128b629abSPhilippe Mathieu-Daudé         features->dev_features =
60228b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_input_feature_map, 0, bitmap);
60328b629abSPhilippe Mathieu-Daudé         break;
60428b629abSPhilippe Mathieu-Daudé #endif
60528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_USER_FS
60628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_FS:
60728b629abSPhilippe Mathieu-Daudé         features->dev_features =
60828b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_fs_feature_map, 0, bitmap);
60928b629abSPhilippe Mathieu-Daudé         break;
61028b629abSPhilippe Mathieu-Daudé #endif
61128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_VSOCK
61228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_VSOCK:
61328b629abSPhilippe Mathieu-Daudé         features->dev_features =
61428b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_vsock_feature_map, 0, bitmap);
61528b629abSPhilippe Mathieu-Daudé         break;
61628b629abSPhilippe Mathieu-Daudé #endif
61728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_CRYPTO
61828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CRYPTO:
61928b629abSPhilippe Mathieu-Daudé         features->dev_features =
62028b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_crypto_feature_map, 0, bitmap);
62128b629abSPhilippe Mathieu-Daudé         break;
62228b629abSPhilippe Mathieu-Daudé #endif
62328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_MEM
62428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MEM:
62528b629abSPhilippe Mathieu-Daudé         features->dev_features =
62628b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_mem_feature_map, 0, bitmap);
62728b629abSPhilippe Mathieu-Daudé         break;
62828b629abSPhilippe Mathieu-Daudé #endif
62928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_I2C_ADAPTER
63028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_I2C_ADAPTER:
63128b629abSPhilippe Mathieu-Daudé         features->dev_features =
63228b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_i2c_feature_map, 0, bitmap);
63328b629abSPhilippe Mathieu-Daudé         break;
63428b629abSPhilippe Mathieu-Daudé #endif
63528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_RNG
63628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RNG:
63728b629abSPhilippe Mathieu-Daudé         features->dev_features =
63828b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_rng_feature_map, 0, bitmap);
63928b629abSPhilippe Mathieu-Daudé         break;
64028b629abSPhilippe Mathieu-Daudé #endif
64158f81689SJonah Palmer #ifdef CONFIG_VHOST_USER_GPIO
64258f81689SJonah Palmer     case VIRTIO_ID_GPIO:
64358f81689SJonah Palmer         features->dev_features =
64458f81689SJonah Palmer             CONVERT_FEATURES(strList, virtio_gpio_feature_map, 0, bitmap);
64558f81689SJonah Palmer         break;
64658f81689SJonah Palmer #endif
64728b629abSPhilippe Mathieu-Daudé     /* No features */
64828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_9P:
64928b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_PMEM:
65028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_IOMEM:
65128b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RPMSG:
65228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CLOCK:
65328b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MAC80211_WLAN:
65428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MAC80211_HWSIM:
65528b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RPROC_SERIAL:
65628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MEMORY_BALLOON:
65728b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CAIF:
65828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SIGNAL_DIST:
65928b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_PSTORE:
66028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SOUND:
66128b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_BT:
66228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RPMB:
66328b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_VIDEO_ENCODER:
66428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_VIDEO_DECODER:
66528b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SCMI:
66628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_NITRO_SEC_MOD:
66728b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_WATCHDOG:
66828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CAN:
66928b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_DMABUF:
67028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_PARAM_SERV:
67128b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_AUDIO_POLICY:
67228b629abSPhilippe Mathieu-Daudé         break;
67328b629abSPhilippe Mathieu-Daudé     default:
67428b629abSPhilippe Mathieu-Daudé         g_assert_not_reached();
67528b629abSPhilippe Mathieu-Daudé     }
67628b629abSPhilippe Mathieu-Daudé 
67728b629abSPhilippe Mathieu-Daudé     features->has_unknown_dev_features = bitmap != 0;
67828b629abSPhilippe Mathieu-Daudé     if (features->has_unknown_dev_features) {
67928b629abSPhilippe Mathieu-Daudé         features->unknown_dev_features = bitmap;
68028b629abSPhilippe Mathieu-Daudé     }
68128b629abSPhilippe Mathieu-Daudé 
68228b629abSPhilippe Mathieu-Daudé     return features;
68328b629abSPhilippe Mathieu-Daudé }
6849d94c213SPhilippe Mathieu-Daudé 
685b532c684SJonah Palmer static int query_dev_child(Object *child, void *opaque)
686b532c684SJonah Palmer {
687b532c684SJonah Palmer     VirtioInfoList **vdevs = opaque;
688b532c684SJonah Palmer     Object *dev = object_dynamic_cast(child, TYPE_VIRTIO_DEVICE);
689b532c684SJonah Palmer     if (dev != NULL && DEVICE(dev)->realized) {
690b532c684SJonah Palmer         VirtIODevice *vdev = VIRTIO_DEVICE(dev);
691b532c684SJonah Palmer         VirtioInfo *info = g_new(VirtioInfo, 1);
692b532c684SJonah Palmer 
693b532c684SJonah Palmer         /* Get canonical path & name of device */
694b532c684SJonah Palmer         info->path = object_get_canonical_path(dev);
695b532c684SJonah Palmer         info->name = g_strdup(vdev->name);
696b532c684SJonah Palmer         QAPI_LIST_PREPEND(*vdevs, info);
697b532c684SJonah Palmer     }
698b532c684SJonah Palmer     return 0;
699b532c684SJonah Palmer }
700b532c684SJonah Palmer 
7019d94c213SPhilippe Mathieu-Daudé VirtioInfoList *qmp_x_query_virtio(Error **errp)
7029d94c213SPhilippe Mathieu-Daudé {
703b532c684SJonah Palmer     VirtioInfoList *vdevs = NULL;
7049d94c213SPhilippe Mathieu-Daudé 
705b532c684SJonah Palmer     /* Query the QOM composition tree recursively for virtio devices */
706b532c684SJonah Palmer     object_child_foreach_recursive(object_get_root(), query_dev_child, &vdevs);
707b532c684SJonah Palmer     if (vdevs == NULL) {
708b532c684SJonah Palmer         error_setg(errp, "No virtio devices found");
7099d94c213SPhilippe Mathieu-Daudé     }
710b532c684SJonah Palmer     return vdevs;
7119d94c213SPhilippe Mathieu-Daudé }
7129d94c213SPhilippe Mathieu-Daudé 
7139d94c213SPhilippe Mathieu-Daudé VirtIODevice *qmp_find_virtio_device(const char *path)
7149d94c213SPhilippe Mathieu-Daudé {
715b532c684SJonah Palmer     /* Verify the canonical path is a realized virtio device */
716b532c684SJonah Palmer     Object *dev = object_dynamic_cast(object_resolve_path(path, NULL),
717b532c684SJonah Palmer                                       TYPE_VIRTIO_DEVICE);
718b532c684SJonah Palmer     if (!dev || !DEVICE(dev)->realized) {
7199d94c213SPhilippe Mathieu-Daudé         return NULL;
7209d94c213SPhilippe Mathieu-Daudé     }
721b532c684SJonah Palmer     return VIRTIO_DEVICE(dev);
7229d94c213SPhilippe Mathieu-Daudé }
7239d94c213SPhilippe Mathieu-Daudé 
7249d94c213SPhilippe Mathieu-Daudé VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
7259d94c213SPhilippe Mathieu-Daudé {
7269d94c213SPhilippe Mathieu-Daudé     VirtIODevice *vdev;
7279d94c213SPhilippe Mathieu-Daudé     VirtioStatus *status;
7289d94c213SPhilippe Mathieu-Daudé 
7299d94c213SPhilippe Mathieu-Daudé     vdev = qmp_find_virtio_device(path);
7309d94c213SPhilippe Mathieu-Daudé     if (vdev == NULL) {
731b532c684SJonah Palmer         error_setg(errp, "Path %s is not a realized VirtIODevice", path);
7329d94c213SPhilippe Mathieu-Daudé         return NULL;
7339d94c213SPhilippe Mathieu-Daudé     }
7349d94c213SPhilippe Mathieu-Daudé 
7359d94c213SPhilippe Mathieu-Daudé     status = g_new0(VirtioStatus, 1);
7369d94c213SPhilippe Mathieu-Daudé     status->name = g_strdup(vdev->name);
7379d94c213SPhilippe Mathieu-Daudé     status->device_id = vdev->device_id;
7389d94c213SPhilippe Mathieu-Daudé     status->vhost_started = vdev->vhost_started;
7399d94c213SPhilippe Mathieu-Daudé     status->guest_features = qmp_decode_features(vdev->device_id,
7409d94c213SPhilippe Mathieu-Daudé                                                  vdev->guest_features);
7419d94c213SPhilippe Mathieu-Daudé     status->host_features = qmp_decode_features(vdev->device_id,
7429d94c213SPhilippe Mathieu-Daudé                                                 vdev->host_features);
7439d94c213SPhilippe Mathieu-Daudé     status->backend_features = qmp_decode_features(vdev->device_id,
7449d94c213SPhilippe Mathieu-Daudé                                                    vdev->backend_features);
7459d94c213SPhilippe Mathieu-Daudé 
7469d94c213SPhilippe Mathieu-Daudé     switch (vdev->device_endian) {
7479d94c213SPhilippe Mathieu-Daudé     case VIRTIO_DEVICE_ENDIAN_LITTLE:
7489d94c213SPhilippe Mathieu-Daudé         status->device_endian = g_strdup("little");
7499d94c213SPhilippe Mathieu-Daudé         break;
7509d94c213SPhilippe Mathieu-Daudé     case VIRTIO_DEVICE_ENDIAN_BIG:
7519d94c213SPhilippe Mathieu-Daudé         status->device_endian = g_strdup("big");
7529d94c213SPhilippe Mathieu-Daudé         break;
7539d94c213SPhilippe Mathieu-Daudé     default:
7549d94c213SPhilippe Mathieu-Daudé         status->device_endian = g_strdup("unknown");
7559d94c213SPhilippe Mathieu-Daudé         break;
7569d94c213SPhilippe Mathieu-Daudé     }
7579d94c213SPhilippe Mathieu-Daudé 
7589d94c213SPhilippe Mathieu-Daudé     status->num_vqs = virtio_get_num_queues(vdev);
7599d94c213SPhilippe Mathieu-Daudé     status->status = qmp_decode_status(vdev->status);
7609d94c213SPhilippe Mathieu-Daudé     status->isr = vdev->isr;
7619d94c213SPhilippe Mathieu-Daudé     status->queue_sel = vdev->queue_sel;
7629d94c213SPhilippe Mathieu-Daudé     status->vm_running = vdev->vm_running;
7639d94c213SPhilippe Mathieu-Daudé     status->broken = vdev->broken;
7649d94c213SPhilippe Mathieu-Daudé     status->disabled = vdev->disabled;
7659d94c213SPhilippe Mathieu-Daudé     status->use_started = vdev->use_started;
7669d94c213SPhilippe Mathieu-Daudé     status->started = vdev->started;
7679d94c213SPhilippe Mathieu-Daudé     status->start_on_kick = vdev->start_on_kick;
7689d94c213SPhilippe Mathieu-Daudé     status->disable_legacy_check = vdev->disable_legacy_check;
7699d94c213SPhilippe Mathieu-Daudé     status->bus_name = g_strdup(vdev->bus_name);
7709d94c213SPhilippe Mathieu-Daudé     status->use_guest_notifier_mask = vdev->use_guest_notifier_mask;
7719d94c213SPhilippe Mathieu-Daudé 
7729d94c213SPhilippe Mathieu-Daudé     if (vdev->vhost_started) {
7739d94c213SPhilippe Mathieu-Daudé         VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
7749d94c213SPhilippe Mathieu-Daudé         struct vhost_dev *hdev = vdc->get_vhost(vdev);
7759d94c213SPhilippe Mathieu-Daudé 
7769d94c213SPhilippe Mathieu-Daudé         status->vhost_dev = g_new0(VhostStatus, 1);
7779d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->n_mem_sections = hdev->n_mem_sections;
7789d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
7799d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->nvqs = hdev->nvqs;
7809d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->vq_index = hdev->vq_index;
7819d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->features =
7829d94c213SPhilippe Mathieu-Daudé             qmp_decode_features(vdev->device_id, hdev->features);
7839d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->acked_features =
7849d94c213SPhilippe Mathieu-Daudé             qmp_decode_features(vdev->device_id, hdev->acked_features);
7859d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->backend_features =
7869d94c213SPhilippe Mathieu-Daudé             qmp_decode_features(vdev->device_id, hdev->backend_features);
7879d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->protocol_features =
7889d94c213SPhilippe Mathieu-Daudé             qmp_decode_protocols(hdev->protocol_features);
7899d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->max_queues = hdev->max_queues;
7909d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->backend_cap = hdev->backend_cap;
7919d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->log_enabled = hdev->log_enabled;
7929d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->log_size = hdev->log_size;
7939d94c213SPhilippe Mathieu-Daudé     }
7949d94c213SPhilippe Mathieu-Daudé 
7959d94c213SPhilippe Mathieu-Daudé     return status;
7969d94c213SPhilippe Mathieu-Daudé }
7979d94c213SPhilippe Mathieu-Daudé 
7989d94c213SPhilippe Mathieu-Daudé VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path,
7999d94c213SPhilippe Mathieu-Daudé                                                             uint16_t queue,
8009d94c213SPhilippe Mathieu-Daudé                                                             Error **errp)
8019d94c213SPhilippe Mathieu-Daudé {
8029d94c213SPhilippe Mathieu-Daudé     VirtIODevice *vdev;
8039d94c213SPhilippe Mathieu-Daudé     VirtVhostQueueStatus *status;
8049d94c213SPhilippe Mathieu-Daudé 
8059d94c213SPhilippe Mathieu-Daudé     vdev = qmp_find_virtio_device(path);
8069d94c213SPhilippe Mathieu-Daudé     if (vdev == NULL) {
8079d94c213SPhilippe Mathieu-Daudé         error_setg(errp, "Path %s is not a VirtIODevice", path);
8089d94c213SPhilippe Mathieu-Daudé         return NULL;
8099d94c213SPhilippe Mathieu-Daudé     }
8109d94c213SPhilippe Mathieu-Daudé 
8119d94c213SPhilippe Mathieu-Daudé     if (!vdev->vhost_started) {
8129d94c213SPhilippe Mathieu-Daudé         error_setg(errp, "Error: vhost device has not started yet");
8139d94c213SPhilippe Mathieu-Daudé         return NULL;
8149d94c213SPhilippe Mathieu-Daudé     }
8159d94c213SPhilippe Mathieu-Daudé 
8169d94c213SPhilippe Mathieu-Daudé     VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
8179d94c213SPhilippe Mathieu-Daudé     struct vhost_dev *hdev = vdc->get_vhost(vdev);
8189d94c213SPhilippe Mathieu-Daudé 
8199d94c213SPhilippe Mathieu-Daudé     if (queue < hdev->vq_index || queue >= hdev->vq_index + hdev->nvqs) {
8209d94c213SPhilippe Mathieu-Daudé         error_setg(errp, "Invalid vhost virtqueue number %d", queue);
8219d94c213SPhilippe Mathieu-Daudé         return NULL;
8229d94c213SPhilippe Mathieu-Daudé     }
8239d94c213SPhilippe Mathieu-Daudé 
8249d94c213SPhilippe Mathieu-Daudé     status = g_new0(VirtVhostQueueStatus, 1);
8259d94c213SPhilippe Mathieu-Daudé     status->name = g_strdup(vdev->name);
8269d94c213SPhilippe Mathieu-Daudé     status->kick = hdev->vqs[queue].kick;
8279d94c213SPhilippe Mathieu-Daudé     status->call = hdev->vqs[queue].call;
8289d94c213SPhilippe Mathieu-Daudé     status->desc = (uintptr_t)hdev->vqs[queue].desc;
8299d94c213SPhilippe Mathieu-Daudé     status->avail = (uintptr_t)hdev->vqs[queue].avail;
8309d94c213SPhilippe Mathieu-Daudé     status->used = (uintptr_t)hdev->vqs[queue].used;
8319d94c213SPhilippe Mathieu-Daudé     status->num = hdev->vqs[queue].num;
8329d94c213SPhilippe Mathieu-Daudé     status->desc_phys = hdev->vqs[queue].desc_phys;
8339d94c213SPhilippe Mathieu-Daudé     status->desc_size = hdev->vqs[queue].desc_size;
8349d94c213SPhilippe Mathieu-Daudé     status->avail_phys = hdev->vqs[queue].avail_phys;
8359d94c213SPhilippe Mathieu-Daudé     status->avail_size = hdev->vqs[queue].avail_size;
8369d94c213SPhilippe Mathieu-Daudé     status->used_phys = hdev->vqs[queue].used_phys;
8379d94c213SPhilippe Mathieu-Daudé     status->used_size = hdev->vqs[queue].used_size;
8389d94c213SPhilippe Mathieu-Daudé 
8399d94c213SPhilippe Mathieu-Daudé     return status;
8409d94c213SPhilippe Mathieu-Daudé }
841