Skip to content
Merged
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions src/balloon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use volatile::access::{ReadOnly, ReadWrite};
use volatile_macro::VolatileFieldAccess;

pub use super::features::balloon::F;
use crate::le32;

/// Traditional Memory Balloon Device Configuration Layout
///
/// Use [`ConfigVolatileFieldAccess`] to work with this struct.
#[doc(alias = "virtio_balloon_config")]
#[cfg_attr(
feature = "zerocopy",
derive(
zerocopy_derive::KnownLayout,
zerocopy_derive::Immutable,
zerocopy_derive::FromBytes,
)
)]
#[derive(VolatileFieldAccess)]
#[repr(C)]
pub struct Config {
#[access(ReadOnly)]
num_pages: le32,

#[access(ReadWrite)]
actual: le32,

#[access(ReadOnly)]
free_page_hint_cmd_id: le32,

#[access(ReadWrite)]
poison_val: le32,
}
49 changes: 49 additions & 0 deletions src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,55 @@ pub mod vsock {
impl crate::FeatureBits for F {}
}

pub mod balloon {
use crate::le128;

feature_bits! {
/// Traditional Memory Balloon Device Feature Bits
#[doc(alias = "VIRTIO_BALLOON_F")]
pub struct F: le128 {
/// Host has to be told before pages from the balloon are used.
#[doc(alias = "VIRTIO_BALLOON_F_MUST_TELL_HOST")]
const MUST_TELL_HOST = 1 << 0;

/// A virtqueue for reporting guest memory statistics is present.
#[doc(alias = "VIRTIO_BALLOON_F_STATS_VQ")]
const STATS_VQ = 1 << 1;

/// Deflate balloon on guest out of memory condition.
///
/// <div class="warning">
///
/// The specification is a bit confusing on this feature, see [oasis-tcs/virtio-spec#228](https://github.com/oasis-tcs/virtio-spec/issues/228).
///
/// </div>
#[doc(alias = "VIRTIO_BALLOON_F_DEFLATE_ON_OOM")]
const DEFLATE_ON_OOM = 1 << 2;

/// The device has support for free page hinting.
/// A virtqueue for providing hints as to what memory is currently free is present.
/// Configuration field [`free_page_hint_cmd_id`](`crate::balloon::ConfigVolatileFieldAccess::free_page_hint_cmd_id`) is valid.
#[doc(alias = "VIRTIO_BALLOON_F_FREE_PAGE_HINT")]
const FREE_PAGE_HINT = 1 << 3;

/// A hint to the device, that the driver will immediately write
/// [`poison_val`] to pages after deflating them.
/// Configuration field [`poison_val`] is valid.
///
/// [`poison_val`]: crate::balloon::ConfigVolatileFieldAccess::poison_val
#[doc(alias = "VIRTIO_BALLOON_F_PAGE_POISON")]
const PAGE_POISON = 1 << 4;

/// The device has support for free page reporting.
/// A virtqueue for reporting free guest memory is present.
#[doc(alias = "VIRTIO_BALLOON_F_PAGE_REPORTING")]
const PAGE_REPORTING = 1 << 5;
}
}

impl crate::FeatureBits for F {}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
//! | Block Device | ❌ | |
//! | Console Device | ✅ | [`console`] |
//! | Entropy Device | ❌ | |
//! | Traditional Memory Balloon Device | | |
//! | Traditional Memory Balloon Device | | [`balloon`] |
//! | SCSI Host Device | ❌ | |
//! | GPU Device | ❌ | |
//! | Input Device | ❌ | |
Expand All @@ -94,6 +94,7 @@ extern crate alloc;
mod bitflags;
#[macro_use]
pub mod volatile;
pub mod balloon;
pub mod console;
#[cfg(any(feature = "mmio", feature = "pci"))]
mod driver_notifications;
Expand Down