Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtio.h: add some user-friendly apis #622

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/include/openamp/virtio.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ struct virtio_device_id {
*/
#define VIRTIO_F_NOTIFY_ON_EMPTY (1 << 24)

/*
* This feature indicates that the device accepts arbitrary
* descriptor layouts.
*/
#define VIRTIO_F_ANY_LAYOUT (1 << 27)

/*
* The guest should never negotiate this feature; it
* is used to detect faulty drivers.
Expand Down Expand Up @@ -431,6 +437,9 @@ static inline int virtio_get_features(struct virtio_device *vdev,
return -ENXIO;

*features = vdev->func->get_features(vdev);
if (VIRTIO_ROLE_IS_DEVICE(vdev))
vdev->features = *features;

return 0;
}

Expand Down Expand Up @@ -499,6 +508,23 @@ static inline int virtio_reset_device(struct virtio_device *vdev)
return 0;
}

/**
* @brief Check if the virtio device support a specific feature.
*
* @param vdev Pointer to device structure.
* @param feature_bit Feature bit to check.
*
* @return true if the feature is supported, otherwise false.
*/
static inline bool virtio_has_feature(struct virtio_device *vdev,
unsigned int feature_bit)
{
if (!vdev)
return false;

return (vdev->features & (1UL << feature_bit)) != 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function return valid value only if virtio_negotiate_features has been called first . That also means that it does not work for virtio device role.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I consider assign back the final features to vdev->features when call virtio_get_feature() for VIRTIO_DEVICE side, so VIRTIO_DEVICE can use this virtio_has_feature() after called virtio_get_feature(). What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, @arnopo Could you review again?


#if defined __cplusplus
}
#endif
Expand Down