From b7cadeb7ce7631a7ac476ed4be0440a551c002f5 Mon Sep 17 00:00:00 2001 From: Arnaud Pouliquen Date: Fri, 14 Jun 2024 11:45:12 +0200 Subject: [PATCH] lib: virtio: Rework macros VIRTIO_ROLE_IS_DEVICE and VIRTIO_ROLE_IS_DRIVER The virtio.h header can be included by applications. In such cases, VIRTIO_DRIVER_SUPPORT and VIRTIO_DEVICE_SUPPORT, which are used to optimize the library, may not be defined in the application. Define default VIRTIO_ROLE_IS_DEVICE and VIRTIO_ROLE_IS_DRIVER macros that do not check for VIRTIO_DEVICE_SUPPORT or VIRTIO_DRIVER_SUPPORT if they are not defined. Signed-off-by: Arnaud Pouliquen --- lib/include/openamp/virtio.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/include/openamp/virtio.h b/lib/include/openamp/virtio.h index f854140a..c4d4927b 100644 --- a/lib/include/openamp/virtio.h +++ b/lib/include/openamp/virtio.h @@ -84,10 +84,21 @@ extern "C" { #define VIRTIO_ENABLED(option) (option == 1) +#ifdef VIRTIO_DRIVER_SUPPORT #define VIRTIO_ROLE_IS_DRIVER(vdev) \ (VIRTIO_ENABLED(VIRTIO_DRIVER_SUPPORT) && (vdev->role) == VIRTIO_DEV_DRIVER) +#else +/* Default definition without code size optimization */ +#define VIRTIO_ROLE_IS_DRIVER(vdev) (vdev->role == VIRTIO_DEV_DRIVER) +#endif + +#ifdef VIRTIO_DEVICE_SUPPORT #define VIRTIO_ROLE_IS_DEVICE(vdev) \ (VIRTIO_ENABLED(VIRTIO_DEVICE_SUPPORT) && (vdev->role) == VIRTIO_DEV_DEVICE) +#else +/* Default definition without code size optimization */ +#define VIRTIO_ROLE_IS_DEVICE(vdev) (vdev->role == VIRTIO_DEV_DEVICE) +#endif /** @brief Virtio device identifier. */ struct virtio_device_id {