[PATCH v3 06/11] hw/virtio: Check target supports legacy bi-endianness at runtime

Philippe Mathieu-Daudé posted 11 patches 1 week ago
There is a newer version of this series
[PATCH v3 06/11] hw/virtio: Check target supports legacy bi-endianness at runtime
Posted by Philippe Mathieu-Daudé 1 week ago
Convert build-time check by a runtime one using the TargetInfo API.

Inspired-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/virtio/virtio.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 627a929b063..d64ecc29a89 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -3233,15 +3233,17 @@ int virtio_set_features_ex(VirtIODevice *vdev, const uint64_t *features)
     return ret;
 }
 
-#if defined(TARGET_PPC64) || defined(TARGET_ARM)
-#define LEGACY_VIRTIO_IS_BIENDIAN 1
-#endif
+static bool target_is_legacy_virtio_biendian(void)
+{
+    return target_ppc64() || target_base_arm();
+}
 
 static bool virtio_access_is_big_endian(const VirtIODevice *vdev)
 {
-#if defined(LEGACY_VIRTIO_IS_BIENDIAN)
-    return virtio_is_big_endian(vdev);
-#elif TARGET_BIG_ENDIAN
+    if (target_is_legacy_virtio_biendian()) {
+        return virtio_is_big_endian(vdev);
+    }
+#if TARGET_BIG_ENDIAN
     if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
         /* Devices conforming to VIRTIO 1.0 or later are always LE. */
         return false;
-- 
2.52.0