@samitouri / QOSamiQemu / commits / 4a0d0cd942

hw/virtio/virtio-qmp: make compilation unit common

All compile time conditionals have no impact at runtime, since they are representing only possible features for devices present at runtime. In case they are not present, associated features table will never be used. In case they are present but some features are not, matching bits will never be enabled, so those entries will be unused. Thus, simply expose everything and call it a day. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> Link: https://lore.kernel.org/qemu-devel/20260225041948.52929-6-philmd@linaro.org Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>

Pierrick Bouvier committed Feb 25, 2026 at 05:19 UTC 4a0d0cd9429898d8dda7611f7b5e2f0ec769cb02
2 files changed +1 -71
hw/virtio/meson.build
+1 -1
@@ -11,7 +11,7 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')
11
12 specific_virtio_ss = ss.source_set()
13 specific_virtio_ss.add(files('virtio.c'))
14 -specific_virtio_ss.add(files('virtio-qmp.c'))
14 +system_virtio_ss.add(files('virtio-qmp.c'))
15
16 if have_vhost
17 system_virtio_ss.add(files('vhost.c'))
hw/virtio/virtio-qmp.c
-70
@@ -33,21 +33,17 @@
33 #include "standard-headers/linux/virtio_vsock.h"
34 #include "standard-headers/linux/virtio_gpio.h"
35
36 -#include CONFIG_DEVICES
37 -
36 #define FEATURE_ENTRY(name, desc) (qmp_virtio_feature_map_t) \
37 { .virtio_bit = name, .feature_desc = desc }
38
39 /* Virtio transport features mapping */
40 static const qmp_virtio_feature_map_t virtio_transport_map[] = {
41 /* Virtio device transport features */
44 -#ifndef VIRTIO_CONFIG_NO_LEGACY
42 FEATURE_ENTRY(VIRTIO_F_NOTIFY_ON_EMPTY, \
43 "VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. "
44 "descs. on VQ"),
45 FEATURE_ENTRY(VIRTIO_F_ANY_LAYOUT, \
46 "VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts"),
50 -#endif /* !VIRTIO_CONFIG_NO_LEGACY */
47 FEATURE_ENTRY(VIRTIO_F_VERSION_1, \
48 "VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)"),
49 FEATURE_ENTRY(VIRTIO_F_IOMMU_PLATFORM, \
@@ -149,7 +145,6 @@ static const qmp_virtio_feature_map_t virtio_config_status_map[] = {
145 };
146
147 /* virtio-blk features mapping */
152 -#ifdef CONFIG_VIRTIO_BLK
148 static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
149 FEATURE_ENTRY(VIRTIO_BLK_F_SIZE_MAX, \
150 "VIRTIO_BLK_F_SIZE_MAX: Max segment size is size_max"),
@@ -173,7 +168,6 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
168 "VIRTIO_BLK_F_SECURE_ERASE: Secure erase supported"),
169 FEATURE_ENTRY(VIRTIO_BLK_F_ZONED, \
170 "VIRTIO_BLK_F_ZONED: Zoned block devices"),
176 -#ifndef VIRTIO_BLK_NO_LEGACY
171 FEATURE_ENTRY(VIRTIO_BLK_F_BARRIER, \
172 "VIRTIO_BLK_F_BARRIER: Request barriers supported"),
173 FEATURE_ENTRY(VIRTIO_BLK_F_SCSI, \
@@ -183,7 +177,6 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
177 FEATURE_ENTRY(VIRTIO_BLK_F_CONFIG_WCE, \
178 "VIRTIO_BLK_F_CONFIG_WCE: Cache writeback and writethrough modes "
179 "supported"),
186 -#endif /* !VIRTIO_BLK_NO_LEGACY */
180 FEATURE_ENTRY(VHOST_F_LOG_ALL, \
181 "VHOST_F_LOG_ALL: Logging write descriptors supported"),
182 FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
@@ -191,10 +184,8 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {
184 "negotiation supported"),
185 { -1, "" }
186 };
194 -#endif
187
188 /* virtio-serial features mapping */
197 -#ifdef CONFIG_VIRTIO_SERIAL
189 static const qmp_virtio_feature_map_t virtio_serial_feature_map[] = {
190 FEATURE_ENTRY(VIRTIO_CONSOLE_F_SIZE, \
191 "VIRTIO_CONSOLE_F_SIZE: Host providing console size"),
@@ -204,10 +195,8 @@ static const qmp_virtio_feature_map_t virtio_serial_feature_map[] = {
195 "VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported"),
196 { -1, "" }
197 };
207 -#endif
198
199 /* virtio-gpu features mapping */
210 -#ifdef CONFIG_VIRTIO_GPU
200 static const qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {
201 FEATURE_ENTRY(VIRTIO_GPU_F_VIRGL, \
202 "VIRTIO_GPU_F_VIRGL: Virgl 3D mode supported"),
@@ -227,10 +216,8 @@ static const qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {
216 "negotiation supported"),
217 { -1, "" }
218 };
230 -#endif
219
220 /* virtio-input features mapping */
233 -#ifdef CONFIG_VIRTIO_INPUT
221 static const qmp_virtio_feature_map_t virtio_input_feature_map[] = {
222 FEATURE_ENTRY(VHOST_F_LOG_ALL, \
223 "VHOST_F_LOG_ALL: Logging write descriptors supported"),
@@ -239,10 +226,8 @@ static const qmp_virtio_feature_map_t virtio_input_feature_map[] = {
226 "negotiation supported"),
227 { -1, "" }
228 };
242 -#endif
229
230 /* virtio-net features mapping */
245 -#ifdef CONFIG_VIRTIO_NET
231 static const qmp_virtio_feature_map_t virtio_net_feature_map[] = {
232 FEATURE_ENTRY(VIRTIO_NET_F_CSUM, \
233 "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum "
@@ -313,10 +298,8 @@ static const qmp_virtio_feature_map_t virtio_net_feature_map[] = {
298 "device with same MAC addr. supported"),
299 FEATURE_ENTRY(VIRTIO_NET_F_SPEED_DUPLEX, \
300 "VIRTIO_NET_F_SPEED_DUPLEX: Device set linkspeed and duplex"),
316 -#ifndef VIRTIO_NET_NO_LEGACY
301 FEATURE_ENTRY(VIRTIO_NET_F_GSO, \
302 "VIRTIO_NET_F_GSO: Handling GSO-type packets supported"),
319 -#endif /* !VIRTIO_NET_NO_LEGACY */
303 FEATURE_ENTRY(VHOST_NET_F_VIRTIO_NET_HDR, \
304 "VHOST_NET_F_VIRTIO_NET_HDR: Virtio-net headers for RX and TX "
305 "packets supported"),
@@ -341,10 +324,8 @@ static const qmp_virtio_feature_map_t virtio_net_feature_map[] = {
324 "header"),
325 { -1, "" }
326 };
344 -#endif
327
328 /* virtio-scsi features mapping */
347 -#ifdef CONFIG_VIRTIO_SCSI
329 static const qmp_virtio_feature_map_t virtio_scsi_feature_map[] = {
330 FEATURE_ENTRY(VIRTIO_SCSI_F_INOUT, \
331 "VIRTIO_SCSI_F_INOUT: Requests including read and writable data "
@@ -364,10 +345,8 @@ static const qmp_virtio_feature_map_t virtio_scsi_feature_map[] = {
345 "negotiation supported"),
346 { -1, "" }
347 };
367 -#endif
348
349 /* virtio/vhost-user-fs features mapping */
370 -#ifdef CONFIG_VHOST_USER_FS
350 static const qmp_virtio_feature_map_t virtio_fs_feature_map[] = {
351 FEATURE_ENTRY(VHOST_F_LOG_ALL, \
352 "VHOST_F_LOG_ALL: Logging write descriptors supported"),
@@ -376,10 +355,8 @@ static const qmp_virtio_feature_map_t virtio_fs_feature_map[] = {
355 "negotiation supported"),
356 { -1, "" }
357 };
379 -#endif
358
359 /* virtio/vhost-user-i2c features mapping */
382 -#ifdef CONFIG_VIRTIO_I2C_ADAPTER
360 static const qmp_virtio_feature_map_t virtio_i2c_feature_map[] = {
361 FEATURE_ENTRY(VIRTIO_I2C_F_ZERO_LENGTH_REQUEST, \
362 "VIRTIO_I2C_F_ZERO_LEGNTH_REQUEST: Zero length requests supported"),
@@ -390,10 +367,8 @@ static const qmp_virtio_feature_map_t virtio_i2c_feature_map[] = {
367 "negotiation supported"),
368 { -1, "" }
369 };
393 -#endif
370
371 /* virtio/vhost-vsock features mapping */
396 -#ifdef CONFIG_VHOST_VSOCK
372 static const qmp_virtio_feature_map_t virtio_vsock_feature_map[] = {
373 FEATURE_ENTRY(VIRTIO_VSOCK_F_SEQPACKET, \
374 "VIRTIO_VSOCK_F_SEQPACKET: SOCK_SEQPACKET supported"),
@@ -404,10 +379,8 @@ static const qmp_virtio_feature_map_t virtio_vsock_feature_map[] = {
379 "negotiation supported"),
380 { -1, "" }
381 };
407 -#endif
382
383 /* virtio-balloon features mapping */
410 -#ifdef CONFIG_VIRTIO_BALLOON
384 static const qmp_virtio_feature_map_t virtio_balloon_feature_map[] = {
385 FEATURE_ENTRY(VIRTIO_BALLOON_F_MUST_TELL_HOST, \
386 "VIRTIO_BALLOON_F_MUST_TELL_HOST: Tell host before reclaiming "
@@ -424,19 +397,15 @@ static const qmp_virtio_feature_map_t virtio_balloon_feature_map[] = {
397 "VIRTIO_BALLOON_F_REPORTING: Page reporting VQ enabled"),
398 { -1, "" }
399 };
427 -#endif
400
401 /* virtio-crypto features mapping */
430 -#ifdef CONFIG_VIRTIO_CRYPTO
402 static const qmp_virtio_feature_map_t virtio_crypto_feature_map[] = {
403 FEATURE_ENTRY(VHOST_F_LOG_ALL, \
404 "VHOST_F_LOG_ALL: Logging write descriptors supported"),
405 { -1, "" }
406 };
436 -#endif
407
408 /* virtio-iommu features mapping */
439 -#ifdef CONFIG_VIRTIO_IOMMU
409 static const qmp_virtio_feature_map_t virtio_iommu_feature_map[] = {
410 FEATURE_ENTRY(VIRTIO_IOMMU_F_INPUT_RANGE, \
411 "VIRTIO_IOMMU_F_INPUT_RANGE: Range of available virtual addrs. "
@@ -458,15 +427,11 @@ static const qmp_virtio_feature_map_t virtio_iommu_feature_map[] = {
427 "available"),
428 { -1, "" }
429 };
461 -#endif
430
431 /* virtio-mem features mapping */
464 -#ifdef CONFIG_VIRTIO_MEM
432 static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = {
466 -#ifndef CONFIG_ACPI
433 FEATURE_ENTRY(VIRTIO_MEM_F_ACPI_PXM, \
434 "VIRTIO_MEM_F_ACPI_PXM: node_id is an ACPI PXM and is valid"),
469 -#endif /* !CONFIG_ACPI */
435 FEATURE_ENTRY(VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE, \
436 "VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot be "
437 "accessed"),
@@ -475,10 +440,8 @@ static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = {
440 "plugged when suspending+resuming"),
441 { -1, "" }
442 };
478 -#endif
443
444 /* virtio-rng features mapping */
481 -#ifdef CONFIG_VIRTIO_RNG
445 static const qmp_virtio_feature_map_t virtio_rng_feature_map[] = {
446 FEATURE_ENTRY(VHOST_F_LOG_ALL, \
447 "VHOST_F_LOG_ALL: Logging write descriptors supported"),
@@ -487,10 +450,8 @@ static const qmp_virtio_feature_map_t virtio_rng_feature_map[] = {
450 "negotiation supported"),
451 { -1, "" }
452 };
490 -#endif
453
454 /* virtio/vhost-gpio features mapping */
493 -#ifdef CONFIG_VHOST_USER_GPIO
455 static const qmp_virtio_feature_map_t virtio_gpio_feature_map[] = {
456 FEATURE_ENTRY(VIRTIO_GPIO_F_IRQ, \
457 "VIRTIO_GPIO_F_IRQ: Device supports interrupts on GPIO lines"),
@@ -499,7 +460,6 @@ static const qmp_virtio_feature_map_t virtio_gpio_feature_map[] = {
460 "negotiation supported"),
461 { -1, "" }
462 };
502 -#endif
463
464 #define CONVERT_FEATURES(type, map, is_status, bitmap) \
465 ({ \
@@ -595,96 +555,66 @@ VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id,
555
556 /* device features */
557 switch (device_id) {
598 -#ifdef CONFIG_VIRTIO_SERIAL
558 case VIRTIO_ID_CONSOLE:
559 features->dev_features =
560 CONVERT_FEATURES_EX(strList, virtio_serial_feature_map, bitmap);
561 break;
603 -#endif
604 -#ifdef CONFIG_VIRTIO_BLK
562 case VIRTIO_ID_BLOCK:
563 features->dev_features =
564 CONVERT_FEATURES_EX(strList, virtio_blk_feature_map, bitmap);
565 break;
609 -#endif
610 -#ifdef CONFIG_VIRTIO_GPU
566 case VIRTIO_ID_GPU:
567 features->dev_features =
568 CONVERT_FEATURES_EX(strList, virtio_gpu_feature_map, bitmap);
569 break;
615 -#endif
616 -#ifdef CONFIG_VIRTIO_NET
570 case VIRTIO_ID_NET:
571 features->dev_features =
572 CONVERT_FEATURES_EX(strList, virtio_net_feature_map, bitmap);
573 break;
621 -#endif
622 -#ifdef CONFIG_VIRTIO_SCSI
574 case VIRTIO_ID_SCSI:
575 features->dev_features =
576 CONVERT_FEATURES_EX(strList, virtio_scsi_feature_map, bitmap);
577 break;
627 -#endif
628 -#ifdef CONFIG_VIRTIO_BALLOON
578 case VIRTIO_ID_BALLOON:
579 features->dev_features =
580 CONVERT_FEATURES_EX(strList, virtio_balloon_feature_map, bitmap);
581 break;
633 -#endif
634 -#ifdef CONFIG_VIRTIO_IOMMU
582 case VIRTIO_ID_IOMMU:
583 features->dev_features =
584 CONVERT_FEATURES_EX(strList, virtio_iommu_feature_map, bitmap);
585 break;
639 -#endif
640 -#ifdef CONFIG_VIRTIO_INPUT
586 case VIRTIO_ID_INPUT:
587 features->dev_features =
588 CONVERT_FEATURES_EX(strList, virtio_input_feature_map, bitmap);
589 break;
645 -#endif
646 -#ifdef CONFIG_VHOST_USER_FS
590 case VIRTIO_ID_FS:
591 features->dev_features =
592 CONVERT_FEATURES_EX(strList, virtio_fs_feature_map, bitmap);
593 break;
651 -#endif
652 -#ifdef CONFIG_VHOST_VSOCK
594 case VIRTIO_ID_VSOCK:
595 features->dev_features =
596 CONVERT_FEATURES_EX(strList, virtio_vsock_feature_map, bitmap);
597 break;
657 -#endif
658 -#ifdef CONFIG_VIRTIO_CRYPTO
598 case VIRTIO_ID_CRYPTO:
599 features->dev_features =
600 CONVERT_FEATURES_EX(strList, virtio_crypto_feature_map, bitmap);
601 break;
663 -#endif
664 -#ifdef CONFIG_VIRTIO_MEM
602 case VIRTIO_ID_MEM:
603 features->dev_features =
604 CONVERT_FEATURES_EX(strList, virtio_mem_feature_map, bitmap);
605 break;
669 -#endif
670 -#ifdef CONFIG_VIRTIO_I2C_ADAPTER
606 case VIRTIO_ID_I2C_ADAPTER:
607 features->dev_features =
608 CONVERT_FEATURES_EX(strList, virtio_i2c_feature_map, bitmap);
609 break;
675 -#endif
676 -#ifdef CONFIG_VIRTIO_RNG
610 case VIRTIO_ID_RNG:
611 features->dev_features =
612 CONVERT_FEATURES_EX(strList, virtio_rng_feature_map, bitmap);
613 break;
681 -#endif
682 -#ifdef CONFIG_VHOST_USER_GPIO
614 case VIRTIO_ID_GPIO:
615 features->dev_features =
616 CONVERT_FEATURES_EX(strList, virtio_gpio_feature_map, bitmap);
617 break;
687 -#endif
618 /* No features */
619 case VIRTIO_ID_9P:
620 case VIRTIO_ID_PMEM: