xref: /openbmc/qemu/hw/virtio/virtio-qmp.c (revision 18b0d72fdde6cc88a9e539cb9576fbc78e41c290)
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"),
124*18b0d72fSLaurent Vivier     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_SHARED_OBJECT, \
125*18b0d72fSLaurent Vivier             "VHOST_USER_PROTOCOL_F_SHARED_OBJECT: Backend shared object "
126*18b0d72fSLaurent Vivier             "supported"),
127*18b0d72fSLaurent Vivier     FEATURE_ENTRY(VHOST_USER_PROTOCOL_F_DEVICE_STATE, \
128*18b0d72fSLaurent Vivier             "VHOST_USER_PROTOCOL_F_DEVICE_STATE: Backend device state transfer "
129*18b0d72fSLaurent Vivier             "supported"),
13028b629abSPhilippe Mathieu-Daudé     { -1, "" }
13128b629abSPhilippe Mathieu-Daudé };
13228b629abSPhilippe Mathieu-Daudé 
13328b629abSPhilippe Mathieu-Daudé /* virtio device configuration statuses */
13428b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_config_status_map[] = {
13528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_DRIVER_OK, \
13628b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_DRIVER_OK: Driver setup and ready"),
13728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_FEATURES_OK, \
13828b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_FEATURES_OK: Feature negotiation complete"),
13928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_DRIVER, \
14028b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_DRIVER: Guest OS compatible with device"),
14128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_NEEDS_RESET, \
14228b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_NEEDS_RESET: Irrecoverable error, device needs "
14328b629abSPhilippe Mathieu-Daudé             "reset"),
14428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_FAILED, \
14528b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_FAILED: Error in guest, device failed"),
14628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONFIG_S_ACKNOWLEDGE, \
14728b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONFIG_S_ACKNOWLEDGE: Valid virtio device found"),
14828b629abSPhilippe Mathieu-Daudé     { -1, "" }
14928b629abSPhilippe Mathieu-Daudé };
15028b629abSPhilippe Mathieu-Daudé 
15128b629abSPhilippe Mathieu-Daudé /* virtio-blk features mapping */
15228b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BLK
15328b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
15428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_SIZE_MAX, \
15528b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_SIZE_MAX: Max segment size is size_max"),
15628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_SEG_MAX, \
15728b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_SEG_MAX: Max segments in a request is seg_max"),
15828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_GEOMETRY, \
15928b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_GEOMETRY: Legacy geometry available"),
16028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_RO, \
16128b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_RO: Device is read-only"),
16228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_BLK_SIZE, \
16328b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_BLK_SIZE: Block size of disk available"),
16428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_TOPOLOGY, \
16528b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_TOPOLOGY: Topology information available"),
16628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_MQ, \
16728b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_MQ: Multiqueue supported"),
16828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_DISCARD, \
16928b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_DISCARD: Discard command supported"),
17028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_WRITE_ZEROES, \
17128b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_WRITE_ZEROES: Write zeroes command supported"),
17258f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_BLK_F_SECURE_ERASE, \
17358f81689SJonah Palmer             "VIRTIO_BLK_F_SECURE_ERASE: Secure erase supported"),
1744f736650SSam Li     FEATURE_ENTRY(VIRTIO_BLK_F_ZONED, \
1754f736650SSam Li             "VIRTIO_BLK_F_ZONED: Zoned block devices"),
17628b629abSPhilippe Mathieu-Daudé #ifndef VIRTIO_BLK_NO_LEGACY
17728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_BARRIER, \
17828b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_BARRIER: Request barriers supported"),
17928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_SCSI, \
18028b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_SCSI: SCSI packet commands supported"),
18128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_FLUSH, \
18228b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_FLUSH: Flush command supported"),
18328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BLK_F_CONFIG_WCE, \
18428b629abSPhilippe Mathieu-Daudé             "VIRTIO_BLK_F_CONFIG_WCE: Cache writeback and writethrough modes "
18528b629abSPhilippe Mathieu-Daudé             "supported"),
18628b629abSPhilippe Mathieu-Daudé #endif /* !VIRTIO_BLK_NO_LEGACY */
18728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
18828b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
18928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
19028b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
19128b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
19228b629abSPhilippe Mathieu-Daudé     { -1, "" }
19328b629abSPhilippe Mathieu-Daudé };
19428b629abSPhilippe Mathieu-Daudé #endif
19528b629abSPhilippe Mathieu-Daudé 
19628b629abSPhilippe Mathieu-Daudé /* virtio-serial features mapping */
19728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SERIAL
19828b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_serial_feature_map[] = {
19928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONSOLE_F_SIZE, \
20028b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONSOLE_F_SIZE: Host providing console size"),
20128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONSOLE_F_MULTIPORT, \
20228b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONSOLE_F_MULTIPORT: Multiple ports for device supported"),
20328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_CONSOLE_F_EMERG_WRITE, \
20428b629abSPhilippe Mathieu-Daudé             "VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported"),
20528b629abSPhilippe Mathieu-Daudé     { -1, "" }
20628b629abSPhilippe Mathieu-Daudé };
20728b629abSPhilippe Mathieu-Daudé #endif
20828b629abSPhilippe Mathieu-Daudé 
20928b629abSPhilippe Mathieu-Daudé /* virtio-gpu features mapping */
21028b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_GPU
21128b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {
21228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_VIRGL, \
21328b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_VIRGL: Virgl 3D mode supported"),
21428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_EDID, \
21528b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_EDID: EDID metadata supported"),
21628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_RESOURCE_UUID, \
21728b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_RESOURCE_UUID: Resource UUID assigning supported"),
21828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_RESOURCE_BLOB, \
21928b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_RESOURCE_BLOB: Size-based blob resources supported"),
22028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_GPU_F_CONTEXT_INIT, \
22128b629abSPhilippe Mathieu-Daudé             "VIRTIO_GPU_F_CONTEXT_INIT: Context types and synchronization "
22228b629abSPhilippe Mathieu-Daudé             "timelines supported"),
22328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
22428b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
22528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
22628b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
22728b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
22828b629abSPhilippe Mathieu-Daudé     { -1, "" }
22928b629abSPhilippe Mathieu-Daudé };
23028b629abSPhilippe Mathieu-Daudé #endif
23128b629abSPhilippe Mathieu-Daudé 
23228b629abSPhilippe Mathieu-Daudé /* virtio-input features mapping */
23328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_INPUT
23428b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_input_feature_map[] = {
23528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
23628b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
23728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
23828b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
23928b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
24028b629abSPhilippe Mathieu-Daudé     { -1, "" }
24128b629abSPhilippe Mathieu-Daudé };
24228b629abSPhilippe Mathieu-Daudé #endif
24328b629abSPhilippe Mathieu-Daudé 
24428b629abSPhilippe Mathieu-Daudé /* virtio-net features mapping */
24528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_NET
24628b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_net_feature_map[] = {
24728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CSUM, \
24828b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum "
24928b629abSPhilippe Mathieu-Daudé             "supported"),
25028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_CSUM, \
25128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_CSUM: Driver handling packets with partial "
25228b629abSPhilippe Mathieu-Daudé             "checksum supported"),
25328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \
25428b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_GUEST_OFFLOADS: Control channel offloading "
25528b629abSPhilippe Mathieu-Daudé             "reconfig. supported"),
25628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MTU, \
25728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MTU: Device max MTU reporting supported"),
25828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MAC, \
25928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MAC: Device has given MAC address"),
26028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_TSO4, \
26128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_TSO4: Driver can receive TSOv4"),
26228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_TSO6, \
26328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_TSO6: Driver can receive TSOv6"),
26428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_ECN, \
26528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_ECN: Driver can receive TSO with ECN"),
26628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_UFO, \
26728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_UFO: Driver can receive UFO"),
26828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_TSO4, \
26928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_TSO4: Device can receive TSOv4"),
27028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_TSO6, \
27128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_TSO6: Device can receive TSOv6"),
27228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_ECN, \
27328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_ECN: Device can receive TSO with ECN"),
27428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HOST_UFO, \
27528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HOST_UFO: Device can receive UFO"),
27628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MRG_RXBUF, \
27728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MRG_RXBUF: Driver can merge receive buffers"),
27828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_STATUS, \
27928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_STATUS: Configuration status field available"),
28028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_VQ, \
28128b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_VQ: Control channel available"),
28228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_RX, \
28328b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_RX: Control channel RX mode supported"),
28428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_VLAN, \
28528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_VLAN: Control channel VLAN filtering supported"),
28628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_RX_EXTRA, \
28728b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_RX_EXTRA: Extra RX mode control supported"),
28828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_ANNOUNCE, \
28928b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GUEST_ANNOUNCE: Driver sending gratuitous packets "
29028b629abSPhilippe Mathieu-Daudé             "supported"),
29128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_MQ, \
29228b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_MQ: Multiqueue with automatic receive steering "
29328b629abSPhilippe Mathieu-Daudé             "supported"),
29428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_CTRL_MAC_ADDR, \
29528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_CTRL_MAC_ADDR: MAC address set through control "
29628b629abSPhilippe Mathieu-Daudé             "channel"),
29758f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_NOTF_COAL, \
29858f81689SJonah Palmer             "VIRTIO_NET_F_NOTF_COAL: Device supports coalescing notifications"),
29958f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_USO4, \
30058f81689SJonah Palmer             "VIRTIO_NET_F_GUEST_USO4: Driver can receive USOv4"),
30158f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_GUEST_USO6, \
30258f81689SJonah Palmer             "VIRTIO_NET_F_GUEST_USO4: Driver can receive USOv6"),
30358f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_NET_F_HOST_USO, \
30458f81689SJonah Palmer             "VIRTIO_NET_F_HOST_USO: Device can receive USO"),
30528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_HASH_REPORT, \
30628b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_HASH_REPORT: Hash reporting supported"),
30728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_RSS, \
30828b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_RSS: RSS RX steering supported"),
30928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_RSC_EXT, \
31028b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_RSC_EXT: Extended coalescing info supported"),
31128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_STANDBY, \
31228b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_STANDBY: Device acting as standby for primary "
31328b629abSPhilippe Mathieu-Daudé             "device with same MAC addr. supported"),
31428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_SPEED_DUPLEX, \
31528b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_SPEED_DUPLEX: Device set linkspeed and duplex"),
31628b629abSPhilippe Mathieu-Daudé #ifndef VIRTIO_NET_NO_LEGACY
31728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_NET_F_GSO, \
31828b629abSPhilippe Mathieu-Daudé             "VIRTIO_NET_F_GSO: Handling GSO-type packets supported"),
31928b629abSPhilippe Mathieu-Daudé #endif /* !VIRTIO_NET_NO_LEGACY */
32028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_NET_F_VIRTIO_NET_HDR, \
32128b629abSPhilippe Mathieu-Daudé             "VHOST_NET_F_VIRTIO_NET_HDR: Virtio-net headers for RX and TX "
32228b629abSPhilippe Mathieu-Daudé             "packets supported"),
32328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
32428b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
32528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
32628b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
32728b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
32828b629abSPhilippe Mathieu-Daudé     { -1, "" }
32928b629abSPhilippe Mathieu-Daudé };
33028b629abSPhilippe Mathieu-Daudé #endif
33128b629abSPhilippe Mathieu-Daudé 
33228b629abSPhilippe Mathieu-Daudé /* virtio-scsi features mapping */
33328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SCSI
33428b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_scsi_feature_map[] = {
33528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_INOUT, \
33628b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_INOUT: Requests including read and writable data "
33746e75a77SMichael Tokarev             "buffers supported"),
33828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_HOTPLUG, \
33928b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_HOTPLUG: Reporting and handling hot-plug events "
34028b629abSPhilippe Mathieu-Daudé             "supported"),
34128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_CHANGE, \
34228b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_CHANGE: Reporting and handling LUN changes "
34328b629abSPhilippe Mathieu-Daudé             "supported"),
34428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_SCSI_F_T10_PI, \
34528b629abSPhilippe Mathieu-Daudé             "VIRTIO_SCSI_F_T10_PI: T10 info included in request header"),
34628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
34728b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
34828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
34928b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
35028b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
35128b629abSPhilippe Mathieu-Daudé     { -1, "" }
35228b629abSPhilippe Mathieu-Daudé };
35328b629abSPhilippe Mathieu-Daudé #endif
35428b629abSPhilippe Mathieu-Daudé 
35528b629abSPhilippe Mathieu-Daudé /* virtio/vhost-user-fs features mapping */
35628b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_USER_FS
35728b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_fs_feature_map[] = {
35828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
35928b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
36028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
36128b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
36228b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
36328b629abSPhilippe Mathieu-Daudé     { -1, "" }
36428b629abSPhilippe Mathieu-Daudé };
36528b629abSPhilippe Mathieu-Daudé #endif
36628b629abSPhilippe Mathieu-Daudé 
36728b629abSPhilippe Mathieu-Daudé /* virtio/vhost-user-i2c features mapping */
36828b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_I2C_ADAPTER
36928b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_i2c_feature_map[] = {
37028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, \
37128b629abSPhilippe Mathieu-Daudé             "VIRTIO_I2C_F_ZERO_LEGNTH_REQUEST: Zero length requests supported"),
37228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
37328b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
37428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
37528b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
37628b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
37728b629abSPhilippe Mathieu-Daudé     { -1, "" }
37828b629abSPhilippe Mathieu-Daudé };
37928b629abSPhilippe Mathieu-Daudé #endif
38028b629abSPhilippe Mathieu-Daudé 
38128b629abSPhilippe Mathieu-Daudé /* virtio/vhost-vsock features mapping */
38228b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_VSOCK
38328b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_vsock_feature_map[] = {
38428b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_VSOCK_F_SEQPACKET, \
38528b629abSPhilippe Mathieu-Daudé             "VIRTIO_VSOCK_F_SEQPACKET: SOCK_SEQPACKET supported"),
38628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
38728b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
38828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
38928b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
39028b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
39128b629abSPhilippe Mathieu-Daudé     { -1, "" }
39228b629abSPhilippe Mathieu-Daudé };
39328b629abSPhilippe Mathieu-Daudé #endif
39428b629abSPhilippe Mathieu-Daudé 
39528b629abSPhilippe Mathieu-Daudé /* virtio-balloon features mapping */
39628b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BALLOON
39728b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_balloon_feature_map[] = {
39828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_MUST_TELL_HOST, \
39928b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_MUST_TELL_HOST: Tell host before reclaiming "
40028b629abSPhilippe Mathieu-Daudé             "pages"),
40128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_STATS_VQ, \
40228b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_STATS_VQ: Guest memory stats VQ available"),
40328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_DEFLATE_ON_OOM, \
40428b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_DEFLATE_ON_OOM: Deflate balloon when guest OOM"),
40528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_FREE_PAGE_HINT, \
40628b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_FREE_PAGE_HINT: VQ reporting free pages enabled"),
40728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_PAGE_POISON, \
40828b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_PAGE_POISON: Guest page poisoning enabled"),
40928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_BALLOON_F_REPORTING, \
41028b629abSPhilippe Mathieu-Daudé             "VIRTIO_BALLOON_F_REPORTING: Page reporting VQ enabled"),
41128b629abSPhilippe Mathieu-Daudé     { -1, "" }
41228b629abSPhilippe Mathieu-Daudé };
41328b629abSPhilippe Mathieu-Daudé #endif
41428b629abSPhilippe Mathieu-Daudé 
41528b629abSPhilippe Mathieu-Daudé /* virtio-crypto features mapping */
41628b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_CRYPTO
41728b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_crypto_feature_map[] = {
41828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
41928b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
42028b629abSPhilippe Mathieu-Daudé     { -1, "" }
42128b629abSPhilippe Mathieu-Daudé };
42228b629abSPhilippe Mathieu-Daudé #endif
42328b629abSPhilippe Mathieu-Daudé 
42428b629abSPhilippe Mathieu-Daudé /* virtio-iommu features mapping */
42528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_IOMMU
42628b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_iommu_feature_map[] = {
42728b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_INPUT_RANGE, \
42828b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_INPUT_RANGE: Range of available virtual addrs. "
42928b629abSPhilippe Mathieu-Daudé             "available"),
43028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_DOMAIN_RANGE, \
43128b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_DOMAIN_RANGE: Number of supported domains "
43228b629abSPhilippe Mathieu-Daudé             "available"),
43328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_MAP_UNMAP, \
43428b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_MAP_UNMAP: Map and unmap requests available"),
43528b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_BYPASS, \
43628b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_BYPASS: Endpoints not attached to domains are in "
43728b629abSPhilippe Mathieu-Daudé             "bypass mode"),
43828b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_PROBE, \
43928b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_PROBE: Probe requests available"),
44028b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_MMIO, \
44128b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_MMIO: VIRTIO_IOMMU_MAP_F_MMIO flag available"),
44228b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_IOMMU_F_BYPASS_CONFIG, \
44328b629abSPhilippe Mathieu-Daudé             "VIRTIO_IOMMU_F_BYPASS_CONFIG: Bypass field of IOMMU config "
44428b629abSPhilippe Mathieu-Daudé             "available"),
44528b629abSPhilippe Mathieu-Daudé     { -1, "" }
44628b629abSPhilippe Mathieu-Daudé };
44728b629abSPhilippe Mathieu-Daudé #endif
44828b629abSPhilippe Mathieu-Daudé 
44928b629abSPhilippe Mathieu-Daudé /* virtio-mem features mapping */
45028b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_MEM
45128b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = {
45228b629abSPhilippe Mathieu-Daudé #ifndef CONFIG_ACPI
45328b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_MEM_F_ACPI_PXM, \
45428b629abSPhilippe Mathieu-Daudé             "VIRTIO_MEM_F_ACPI_PXM: node_id is an ACPI PXM and is valid"),
45528b629abSPhilippe Mathieu-Daudé #endif /* !CONFIG_ACPI */
45628b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, \
45728b629abSPhilippe Mathieu-Daudé             "VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot be "
45828b629abSPhilippe Mathieu-Daudé             "accessed"),
4591f5f4905SJuraj Marcin     FEATURE_ENTRY(VIRTIO_MEM_F_PERSISTENT_SUSPEND, \
4601f5f4905SJuraj Marcin             "VIRTIO_MEM_F_PERSISTENT_SUSPND: Plugged memory will remain "
4611f5f4905SJuraj Marcin             "plugged when suspending+resuming"),
46228b629abSPhilippe Mathieu-Daudé     { -1, "" }
46328b629abSPhilippe Mathieu-Daudé };
46428b629abSPhilippe Mathieu-Daudé #endif
46528b629abSPhilippe Mathieu-Daudé 
46628b629abSPhilippe Mathieu-Daudé /* virtio-rng features mapping */
46728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_RNG
46828b629abSPhilippe Mathieu-Daudé static const qmp_virtio_feature_map_t virtio_rng_feature_map[] = {
46928b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_F_LOG_ALL, \
47028b629abSPhilippe Mathieu-Daudé             "VHOST_F_LOG_ALL: Logging write descriptors supported"),
47128b629abSPhilippe Mathieu-Daudé     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
47228b629abSPhilippe Mathieu-Daudé             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
47328b629abSPhilippe Mathieu-Daudé             "negotiation supported"),
47428b629abSPhilippe Mathieu-Daudé     { -1, "" }
47528b629abSPhilippe Mathieu-Daudé };
47628b629abSPhilippe Mathieu-Daudé #endif
47728b629abSPhilippe Mathieu-Daudé 
47858f81689SJonah Palmer /* virtio/vhost-gpio features mapping */
47958f81689SJonah Palmer #ifdef CONFIG_VHOST_USER_GPIO
48058f81689SJonah Palmer static const qmp_virtio_feature_map_t virtio_gpio_feature_map[] = {
48158f81689SJonah Palmer     FEATURE_ENTRY(VIRTIO_GPIO_F_IRQ, \
48258f81689SJonah Palmer             "VIRTIO_GPIO_F_IRQ: Device supports interrupts on GPIO lines"),
48358f81689SJonah Palmer     FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
48458f81689SJonah Palmer             "VHOST_USER_F_PROTOCOL_FEATURES: Vhost-user protocol features "
48558f81689SJonah Palmer             "negotiation supported"),
48658f81689SJonah Palmer     { -1, "" }
48758f81689SJonah Palmer };
48858f81689SJonah Palmer #endif
48958f81689SJonah Palmer 
49028b629abSPhilippe Mathieu-Daudé #define CONVERT_FEATURES(type, map, is_status, bitmap)   \
49128b629abSPhilippe Mathieu-Daudé     ({                                                   \
49228b629abSPhilippe Mathieu-Daudé         type *list = NULL;                               \
49328b629abSPhilippe Mathieu-Daudé         type *node;                                      \
49428b629abSPhilippe Mathieu-Daudé         for (i = 0; map[i].virtio_bit != -1; i++) {      \
49528b629abSPhilippe Mathieu-Daudé             if (is_status) {                             \
49628b629abSPhilippe Mathieu-Daudé                 bit = map[i].virtio_bit;                 \
49728b629abSPhilippe Mathieu-Daudé             }                                            \
49828b629abSPhilippe Mathieu-Daudé             else {                                       \
49928b629abSPhilippe Mathieu-Daudé                 bit = 1ULL << map[i].virtio_bit;         \
50028b629abSPhilippe Mathieu-Daudé             }                                            \
50128b629abSPhilippe Mathieu-Daudé             if ((bitmap & bit) == 0) {                   \
50228b629abSPhilippe Mathieu-Daudé                 continue;                                \
50328b629abSPhilippe Mathieu-Daudé             }                                            \
50428b629abSPhilippe Mathieu-Daudé             node = g_new0(type, 1);                      \
50528b629abSPhilippe Mathieu-Daudé             node->value = g_strdup(map[i].feature_desc); \
50628b629abSPhilippe Mathieu-Daudé             node->next = list;                           \
50728b629abSPhilippe Mathieu-Daudé             list = node;                                 \
50828b629abSPhilippe Mathieu-Daudé             bitmap ^= bit;                               \
50928b629abSPhilippe Mathieu-Daudé         }                                                \
51028b629abSPhilippe Mathieu-Daudé         list;                                            \
51128b629abSPhilippe Mathieu-Daudé     })
51228b629abSPhilippe Mathieu-Daudé 
qmp_decode_status(uint8_t bitmap)51328b629abSPhilippe Mathieu-Daudé VirtioDeviceStatus *qmp_decode_status(uint8_t bitmap)
51428b629abSPhilippe Mathieu-Daudé {
51528b629abSPhilippe Mathieu-Daudé     VirtioDeviceStatus *status;
51628b629abSPhilippe Mathieu-Daudé     uint8_t bit;
51728b629abSPhilippe Mathieu-Daudé     int i;
51828b629abSPhilippe Mathieu-Daudé 
51928b629abSPhilippe Mathieu-Daudé     status = g_new0(VirtioDeviceStatus, 1);
52028b629abSPhilippe Mathieu-Daudé     status->statuses = CONVERT_FEATURES(strList, virtio_config_status_map,
52128b629abSPhilippe Mathieu-Daudé                                         1, bitmap);
52228b629abSPhilippe Mathieu-Daudé     status->has_unknown_statuses = bitmap != 0;
52328b629abSPhilippe Mathieu-Daudé     if (status->has_unknown_statuses) {
52428b629abSPhilippe Mathieu-Daudé         status->unknown_statuses = bitmap;
52528b629abSPhilippe Mathieu-Daudé     }
52628b629abSPhilippe Mathieu-Daudé 
52728b629abSPhilippe Mathieu-Daudé     return status;
52828b629abSPhilippe Mathieu-Daudé }
52928b629abSPhilippe Mathieu-Daudé 
qmp_decode_protocols(uint64_t bitmap)53028b629abSPhilippe Mathieu-Daudé VhostDeviceProtocols *qmp_decode_protocols(uint64_t bitmap)
53128b629abSPhilippe Mathieu-Daudé {
53228b629abSPhilippe Mathieu-Daudé     VhostDeviceProtocols *vhu_protocols;
53328b629abSPhilippe Mathieu-Daudé     uint64_t bit;
53428b629abSPhilippe Mathieu-Daudé     int i;
53528b629abSPhilippe Mathieu-Daudé 
53628b629abSPhilippe Mathieu-Daudé     vhu_protocols = g_new0(VhostDeviceProtocols, 1);
53728b629abSPhilippe Mathieu-Daudé     vhu_protocols->protocols =
53828b629abSPhilippe Mathieu-Daudé                     CONVERT_FEATURES(strList,
53928b629abSPhilippe Mathieu-Daudé                                      vhost_user_protocol_map, 0, bitmap);
54028b629abSPhilippe Mathieu-Daudé     vhu_protocols->has_unknown_protocols = bitmap != 0;
54128b629abSPhilippe Mathieu-Daudé     if (vhu_protocols->has_unknown_protocols) {
54228b629abSPhilippe Mathieu-Daudé         vhu_protocols->unknown_protocols = bitmap;
54328b629abSPhilippe Mathieu-Daudé     }
54428b629abSPhilippe Mathieu-Daudé 
54528b629abSPhilippe Mathieu-Daudé     return vhu_protocols;
54628b629abSPhilippe Mathieu-Daudé }
54728b629abSPhilippe Mathieu-Daudé 
qmp_decode_features(uint16_t device_id,uint64_t bitmap)54828b629abSPhilippe Mathieu-Daudé VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id, uint64_t bitmap)
54928b629abSPhilippe Mathieu-Daudé {
55028b629abSPhilippe Mathieu-Daudé     VirtioDeviceFeatures *features;
55128b629abSPhilippe Mathieu-Daudé     uint64_t bit;
55228b629abSPhilippe Mathieu-Daudé     int i;
55328b629abSPhilippe Mathieu-Daudé 
55428b629abSPhilippe Mathieu-Daudé     features = g_new0(VirtioDeviceFeatures, 1);
55528b629abSPhilippe Mathieu-Daudé     features->has_dev_features = true;
55628b629abSPhilippe Mathieu-Daudé 
55728b629abSPhilippe Mathieu-Daudé     /* transport features */
55828b629abSPhilippe Mathieu-Daudé     features->transports = CONVERT_FEATURES(strList, virtio_transport_map, 0,
55928b629abSPhilippe Mathieu-Daudé                                             bitmap);
56028b629abSPhilippe Mathieu-Daudé 
56128b629abSPhilippe Mathieu-Daudé     /* device features */
56228b629abSPhilippe Mathieu-Daudé     switch (device_id) {
56328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SERIAL
56428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CONSOLE:
56528b629abSPhilippe Mathieu-Daudé         features->dev_features =
56628b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_serial_feature_map, 0, bitmap);
56728b629abSPhilippe Mathieu-Daudé         break;
56828b629abSPhilippe Mathieu-Daudé #endif
56928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BLK
57028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_BLOCK:
57128b629abSPhilippe Mathieu-Daudé         features->dev_features =
57228b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_blk_feature_map, 0, bitmap);
57328b629abSPhilippe Mathieu-Daudé         break;
57428b629abSPhilippe Mathieu-Daudé #endif
57528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_GPU
57628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_GPU:
57728b629abSPhilippe Mathieu-Daudé         features->dev_features =
57828b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_gpu_feature_map, 0, bitmap);
57928b629abSPhilippe Mathieu-Daudé         break;
58028b629abSPhilippe Mathieu-Daudé #endif
58128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_NET
58228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_NET:
58328b629abSPhilippe Mathieu-Daudé         features->dev_features =
58428b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_net_feature_map, 0, bitmap);
58528b629abSPhilippe Mathieu-Daudé         break;
58628b629abSPhilippe Mathieu-Daudé #endif
58728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_SCSI
58828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SCSI:
58928b629abSPhilippe Mathieu-Daudé         features->dev_features =
59028b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_scsi_feature_map, 0, bitmap);
59128b629abSPhilippe Mathieu-Daudé         break;
59228b629abSPhilippe Mathieu-Daudé #endif
59328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_BALLOON
59428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_BALLOON:
59528b629abSPhilippe Mathieu-Daudé         features->dev_features =
59628b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_balloon_feature_map, 0, bitmap);
59728b629abSPhilippe Mathieu-Daudé         break;
59828b629abSPhilippe Mathieu-Daudé #endif
59928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_IOMMU
60028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_IOMMU:
60128b629abSPhilippe Mathieu-Daudé         features->dev_features =
60228b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_iommu_feature_map, 0, bitmap);
60328b629abSPhilippe Mathieu-Daudé         break;
60428b629abSPhilippe Mathieu-Daudé #endif
60528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_INPUT
60628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_INPUT:
60728b629abSPhilippe Mathieu-Daudé         features->dev_features =
60828b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_input_feature_map, 0, bitmap);
60928b629abSPhilippe Mathieu-Daudé         break;
61028b629abSPhilippe Mathieu-Daudé #endif
61128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_USER_FS
61228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_FS:
61328b629abSPhilippe Mathieu-Daudé         features->dev_features =
61428b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_fs_feature_map, 0, bitmap);
61528b629abSPhilippe Mathieu-Daudé         break;
61628b629abSPhilippe Mathieu-Daudé #endif
61728b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VHOST_VSOCK
61828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_VSOCK:
61928b629abSPhilippe Mathieu-Daudé         features->dev_features =
62028b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_vsock_feature_map, 0, bitmap);
62128b629abSPhilippe Mathieu-Daudé         break;
62228b629abSPhilippe Mathieu-Daudé #endif
62328b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_CRYPTO
62428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CRYPTO:
62528b629abSPhilippe Mathieu-Daudé         features->dev_features =
62628b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_crypto_feature_map, 0, bitmap);
62728b629abSPhilippe Mathieu-Daudé         break;
62828b629abSPhilippe Mathieu-Daudé #endif
62928b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_MEM
63028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MEM:
63128b629abSPhilippe Mathieu-Daudé         features->dev_features =
63228b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_mem_feature_map, 0, bitmap);
63328b629abSPhilippe Mathieu-Daudé         break;
63428b629abSPhilippe Mathieu-Daudé #endif
63528b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_I2C_ADAPTER
63628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_I2C_ADAPTER:
63728b629abSPhilippe Mathieu-Daudé         features->dev_features =
63828b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_i2c_feature_map, 0, bitmap);
63928b629abSPhilippe Mathieu-Daudé         break;
64028b629abSPhilippe Mathieu-Daudé #endif
64128b629abSPhilippe Mathieu-Daudé #ifdef CONFIG_VIRTIO_RNG
64228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RNG:
64328b629abSPhilippe Mathieu-Daudé         features->dev_features =
64428b629abSPhilippe Mathieu-Daudé             CONVERT_FEATURES(strList, virtio_rng_feature_map, 0, bitmap);
64528b629abSPhilippe Mathieu-Daudé         break;
64628b629abSPhilippe Mathieu-Daudé #endif
64758f81689SJonah Palmer #ifdef CONFIG_VHOST_USER_GPIO
64858f81689SJonah Palmer     case VIRTIO_ID_GPIO:
64958f81689SJonah Palmer         features->dev_features =
65058f81689SJonah Palmer             CONVERT_FEATURES(strList, virtio_gpio_feature_map, 0, bitmap);
65158f81689SJonah Palmer         break;
65258f81689SJonah Palmer #endif
65328b629abSPhilippe Mathieu-Daudé     /* No features */
65428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_9P:
65528b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_PMEM:
65628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_IOMEM:
65728b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RPMSG:
65828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CLOCK:
65928b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MAC80211_WLAN:
66028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MAC80211_HWSIM:
66128b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RPROC_SERIAL:
66228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_MEMORY_BALLOON:
66328b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CAIF:
66428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SIGNAL_DIST:
66528b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_PSTORE:
66628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SOUND:
66728b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_BT:
66828b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_RPMB:
66928b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_VIDEO_ENCODER:
67028b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_VIDEO_DECODER:
67128b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_SCMI:
67228b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_NITRO_SEC_MOD:
67328b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_WATCHDOG:
67428b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_CAN:
67528b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_DMABUF:
67628b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_PARAM_SERV:
67728b629abSPhilippe Mathieu-Daudé     case VIRTIO_ID_AUDIO_POLICY:
67828b629abSPhilippe Mathieu-Daudé         break;
67928b629abSPhilippe Mathieu-Daudé     default:
68028b629abSPhilippe Mathieu-Daudé         g_assert_not_reached();
68128b629abSPhilippe Mathieu-Daudé     }
68228b629abSPhilippe Mathieu-Daudé 
68328b629abSPhilippe Mathieu-Daudé     features->has_unknown_dev_features = bitmap != 0;
68428b629abSPhilippe Mathieu-Daudé     if (features->has_unknown_dev_features) {
68528b629abSPhilippe Mathieu-Daudé         features->unknown_dev_features = bitmap;
68628b629abSPhilippe Mathieu-Daudé     }
68728b629abSPhilippe Mathieu-Daudé 
68828b629abSPhilippe Mathieu-Daudé     return features;
68928b629abSPhilippe Mathieu-Daudé }
6909d94c213SPhilippe Mathieu-Daudé 
query_dev_child(Object * child,void * opaque)691b532c684SJonah Palmer static int query_dev_child(Object *child, void *opaque)
692b532c684SJonah Palmer {
693b532c684SJonah Palmer     VirtioInfoList **vdevs = opaque;
694b532c684SJonah Palmer     Object *dev = object_dynamic_cast(child, TYPE_VIRTIO_DEVICE);
695b532c684SJonah Palmer     if (dev != NULL && DEVICE(dev)->realized) {
696b532c684SJonah Palmer         VirtIODevice *vdev = VIRTIO_DEVICE(dev);
697b532c684SJonah Palmer         VirtioInfo *info = g_new(VirtioInfo, 1);
698b532c684SJonah Palmer 
699b532c684SJonah Palmer         /* Get canonical path & name of device */
700b532c684SJonah Palmer         info->path = object_get_canonical_path(dev);
701b532c684SJonah Palmer         info->name = g_strdup(vdev->name);
702b532c684SJonah Palmer         QAPI_LIST_PREPEND(*vdevs, info);
703b532c684SJonah Palmer     }
704b532c684SJonah Palmer     return 0;
705b532c684SJonah Palmer }
706b532c684SJonah Palmer 
qmp_x_query_virtio(Error ** errp)7079d94c213SPhilippe Mathieu-Daudé VirtioInfoList *qmp_x_query_virtio(Error **errp)
7089d94c213SPhilippe Mathieu-Daudé {
709b532c684SJonah Palmer     VirtioInfoList *vdevs = NULL;
7109d94c213SPhilippe Mathieu-Daudé 
711b532c684SJonah Palmer     /* Query the QOM composition tree recursively for virtio devices */
712b532c684SJonah Palmer     object_child_foreach_recursive(object_get_root(), query_dev_child, &vdevs);
713b532c684SJonah Palmer     if (vdevs == NULL) {
714b532c684SJonah Palmer         error_setg(errp, "No virtio devices found");
7159d94c213SPhilippe Mathieu-Daudé     }
716b532c684SJonah Palmer     return vdevs;
7179d94c213SPhilippe Mathieu-Daudé }
7189d94c213SPhilippe Mathieu-Daudé 
qmp_find_virtio_device(const char * path)7199d94c213SPhilippe Mathieu-Daudé VirtIODevice *qmp_find_virtio_device(const char *path)
7209d94c213SPhilippe Mathieu-Daudé {
721b532c684SJonah Palmer     /* Verify the canonical path is a realized virtio device */
722b532c684SJonah Palmer     Object *dev = object_dynamic_cast(object_resolve_path(path, NULL),
723b532c684SJonah Palmer                                       TYPE_VIRTIO_DEVICE);
724b532c684SJonah Palmer     if (!dev || !DEVICE(dev)->realized) {
7259d94c213SPhilippe Mathieu-Daudé         return NULL;
7269d94c213SPhilippe Mathieu-Daudé     }
727b532c684SJonah Palmer     return VIRTIO_DEVICE(dev);
7289d94c213SPhilippe Mathieu-Daudé }
7299d94c213SPhilippe Mathieu-Daudé 
qmp_x_query_virtio_status(const char * path,Error ** errp)7309d94c213SPhilippe Mathieu-Daudé VirtioStatus *qmp_x_query_virtio_status(const char *path, Error **errp)
7319d94c213SPhilippe Mathieu-Daudé {
7329d94c213SPhilippe Mathieu-Daudé     VirtIODevice *vdev;
7339d94c213SPhilippe Mathieu-Daudé     VirtioStatus *status;
7349d94c213SPhilippe Mathieu-Daudé 
7359d94c213SPhilippe Mathieu-Daudé     vdev = qmp_find_virtio_device(path);
7369d94c213SPhilippe Mathieu-Daudé     if (vdev == NULL) {
737b532c684SJonah Palmer         error_setg(errp, "Path %s is not a realized VirtIODevice", path);
7389d94c213SPhilippe Mathieu-Daudé         return NULL;
7399d94c213SPhilippe Mathieu-Daudé     }
7409d94c213SPhilippe Mathieu-Daudé 
7419d94c213SPhilippe Mathieu-Daudé     status = g_new0(VirtioStatus, 1);
7429d94c213SPhilippe Mathieu-Daudé     status->name = g_strdup(vdev->name);
7439d94c213SPhilippe Mathieu-Daudé     status->device_id = vdev->device_id;
7449d94c213SPhilippe Mathieu-Daudé     status->vhost_started = vdev->vhost_started;
7459d94c213SPhilippe Mathieu-Daudé     status->guest_features = qmp_decode_features(vdev->device_id,
7469d94c213SPhilippe Mathieu-Daudé                                                  vdev->guest_features);
7479d94c213SPhilippe Mathieu-Daudé     status->host_features = qmp_decode_features(vdev->device_id,
7489d94c213SPhilippe Mathieu-Daudé                                                 vdev->host_features);
7499d94c213SPhilippe Mathieu-Daudé     status->backend_features = qmp_decode_features(vdev->device_id,
7509d94c213SPhilippe Mathieu-Daudé                                                    vdev->backend_features);
7519d94c213SPhilippe Mathieu-Daudé 
7529d94c213SPhilippe Mathieu-Daudé     switch (vdev->device_endian) {
7539d94c213SPhilippe Mathieu-Daudé     case VIRTIO_DEVICE_ENDIAN_LITTLE:
7549d94c213SPhilippe Mathieu-Daudé         status->device_endian = g_strdup("little");
7559d94c213SPhilippe Mathieu-Daudé         break;
7569d94c213SPhilippe Mathieu-Daudé     case VIRTIO_DEVICE_ENDIAN_BIG:
7579d94c213SPhilippe Mathieu-Daudé         status->device_endian = g_strdup("big");
7589d94c213SPhilippe Mathieu-Daudé         break;
7599d94c213SPhilippe Mathieu-Daudé     default:
7609d94c213SPhilippe Mathieu-Daudé         status->device_endian = g_strdup("unknown");
7619d94c213SPhilippe Mathieu-Daudé         break;
7629d94c213SPhilippe Mathieu-Daudé     }
7639d94c213SPhilippe Mathieu-Daudé 
7649d94c213SPhilippe Mathieu-Daudé     status->num_vqs = virtio_get_num_queues(vdev);
7659d94c213SPhilippe Mathieu-Daudé     status->status = qmp_decode_status(vdev->status);
7669d94c213SPhilippe Mathieu-Daudé     status->isr = vdev->isr;
7679d94c213SPhilippe Mathieu-Daudé     status->queue_sel = vdev->queue_sel;
7689d94c213SPhilippe Mathieu-Daudé     status->vm_running = vdev->vm_running;
7699d94c213SPhilippe Mathieu-Daudé     status->broken = vdev->broken;
7709d94c213SPhilippe Mathieu-Daudé     status->disabled = vdev->disabled;
7719d94c213SPhilippe Mathieu-Daudé     status->use_started = vdev->use_started;
7729d94c213SPhilippe Mathieu-Daudé     status->started = vdev->started;
7739d94c213SPhilippe Mathieu-Daudé     status->start_on_kick = vdev->start_on_kick;
7749d94c213SPhilippe Mathieu-Daudé     status->disable_legacy_check = vdev->disable_legacy_check;
7759d94c213SPhilippe Mathieu-Daudé     status->bus_name = g_strdup(vdev->bus_name);
7769d94c213SPhilippe Mathieu-Daudé     status->use_guest_notifier_mask = vdev->use_guest_notifier_mask;
7779d94c213SPhilippe Mathieu-Daudé 
7789d94c213SPhilippe Mathieu-Daudé     if (vdev->vhost_started) {
7799d94c213SPhilippe Mathieu-Daudé         VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
7809d94c213SPhilippe Mathieu-Daudé         struct vhost_dev *hdev = vdc->get_vhost(vdev);
7819d94c213SPhilippe Mathieu-Daudé 
7829d94c213SPhilippe Mathieu-Daudé         status->vhost_dev = g_new0(VhostStatus, 1);
7839d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->n_mem_sections = hdev->n_mem_sections;
7849d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->n_tmp_sections = hdev->n_tmp_sections;
7859d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->nvqs = hdev->nvqs;
7869d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->vq_index = hdev->vq_index;
7879d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->features =
7889d94c213SPhilippe Mathieu-Daudé             qmp_decode_features(vdev->device_id, hdev->features);
7899d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->acked_features =
7909d94c213SPhilippe Mathieu-Daudé             qmp_decode_features(vdev->device_id, hdev->acked_features);
7919d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->backend_features =
7929d94c213SPhilippe Mathieu-Daudé             qmp_decode_features(vdev->device_id, hdev->backend_features);
7939d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->protocol_features =
7949d94c213SPhilippe Mathieu-Daudé             qmp_decode_protocols(hdev->protocol_features);
7959d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->max_queues = hdev->max_queues;
7969d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->backend_cap = hdev->backend_cap;
7979d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->log_enabled = hdev->log_enabled;
7989d94c213SPhilippe Mathieu-Daudé         status->vhost_dev->log_size = hdev->log_size;
7999d94c213SPhilippe Mathieu-Daudé     }
8009d94c213SPhilippe Mathieu-Daudé 
8019d94c213SPhilippe Mathieu-Daudé     return status;
8029d94c213SPhilippe Mathieu-Daudé }
8039d94c213SPhilippe Mathieu-Daudé 
qmp_x_query_virtio_vhost_queue_status(const char * path,uint16_t queue,Error ** errp)8049d94c213SPhilippe Mathieu-Daudé VirtVhostQueueStatus *qmp_x_query_virtio_vhost_queue_status(const char *path,
8059d94c213SPhilippe Mathieu-Daudé                                                             uint16_t queue,
8069d94c213SPhilippe Mathieu-Daudé                                                             Error **errp)
8079d94c213SPhilippe Mathieu-Daudé {
8089d94c213SPhilippe Mathieu-Daudé     VirtIODevice *vdev;
8099d94c213SPhilippe Mathieu-Daudé     VirtVhostQueueStatus *status;
8109d94c213SPhilippe Mathieu-Daudé 
8119d94c213SPhilippe Mathieu-Daudé     vdev = qmp_find_virtio_device(path);
8129d94c213SPhilippe Mathieu-Daudé     if (vdev == NULL) {
8139d94c213SPhilippe Mathieu-Daudé         error_setg(errp, "Path %s is not a VirtIODevice", path);
8149d94c213SPhilippe Mathieu-Daudé         return NULL;
8159d94c213SPhilippe Mathieu-Daudé     }
8169d94c213SPhilippe Mathieu-Daudé 
8179d94c213SPhilippe Mathieu-Daudé     if (!vdev->vhost_started) {
8189d94c213SPhilippe Mathieu-Daudé         error_setg(errp, "Error: vhost device has not started yet");
8199d94c213SPhilippe Mathieu-Daudé         return NULL;
8209d94c213SPhilippe Mathieu-Daudé     }
8219d94c213SPhilippe Mathieu-Daudé 
8229d94c213SPhilippe Mathieu-Daudé     VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev);
8239d94c213SPhilippe Mathieu-Daudé     struct vhost_dev *hdev = vdc->get_vhost(vdev);
8249d94c213SPhilippe Mathieu-Daudé 
8259d94c213SPhilippe Mathieu-Daudé     if (queue < hdev->vq_index || queue >= hdev->vq_index + hdev->nvqs) {
8269d94c213SPhilippe Mathieu-Daudé         error_setg(errp, "Invalid vhost virtqueue number %d", queue);
8279d94c213SPhilippe Mathieu-Daudé         return NULL;
8289d94c213SPhilippe Mathieu-Daudé     }
8299d94c213SPhilippe Mathieu-Daudé 
8309d94c213SPhilippe Mathieu-Daudé     status = g_new0(VirtVhostQueueStatus, 1);
8319d94c213SPhilippe Mathieu-Daudé     status->name = g_strdup(vdev->name);
8329d94c213SPhilippe Mathieu-Daudé     status->kick = hdev->vqs[queue].kick;
8339d94c213SPhilippe Mathieu-Daudé     status->call = hdev->vqs[queue].call;
8349d94c213SPhilippe Mathieu-Daudé     status->desc = (uintptr_t)hdev->vqs[queue].desc;
8359d94c213SPhilippe Mathieu-Daudé     status->avail = (uintptr_t)hdev->vqs[queue].avail;
8369d94c213SPhilippe Mathieu-Daudé     status->used = (uintptr_t)hdev->vqs[queue].used;
8379d94c213SPhilippe Mathieu-Daudé     status->num = hdev->vqs[queue].num;
8389d94c213SPhilippe Mathieu-Daudé     status->desc_phys = hdev->vqs[queue].desc_phys;
8399d94c213SPhilippe Mathieu-Daudé     status->desc_size = hdev->vqs[queue].desc_size;
8409d94c213SPhilippe Mathieu-Daudé     status->avail_phys = hdev->vqs[queue].avail_phys;
8419d94c213SPhilippe Mathieu-Daudé     status->avail_size = hdev->vqs[queue].avail_size;
8429d94c213SPhilippe Mathieu-Daudé     status->used_phys = hdev->vqs[queue].used_phys;
8439d94c213SPhilippe Mathieu-Daudé     status->used_size = hdev->vqs[queue].used_size;
8449d94c213SPhilippe Mathieu-Daudé 
8459d94c213SPhilippe Mathieu-Daudé     return status;
8469d94c213SPhilippe Mathieu-Daudé }
847