Skip to content

Commit

Permalink
lib: virtio: Rework macros VIRTIO_ROLE_IS_DEVICE and VIRTIO_ROLE_IS_D…
Browse files Browse the repository at this point in the history
…RIVER

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 <[email protected]>
  • Loading branch information
arnopo committed Jun 28, 2024
1 parent 04a4185 commit b7cadeb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/include/openamp/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b7cadeb

Please sign in to comment.