2025-03-06 16:35:21 +08:00

43 lines
1.3 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// SPDX-License-Identifier: MPL-2.0
use aster_util::safe_ptr::SafePtr;
use bitflags::bitflags;
use ostd::{io_mem::IoMem, mm::PodOnce, Pod};
use crate::transport::VirtioTransport;
bitflags! {
pub struct VsockFeatures: u64 {
const VIRTIO_VSOCK_F_STREAM = 1 << 0; // stream socket type is supported.
const VIRTIO_VSOCK_F_SEQPACKET = 1 << 1; //seqpacket socket type is not supported now.
}
}
impl VsockFeatures {
pub const fn supported_features() -> Self {
VsockFeatures::VIRTIO_VSOCK_F_STREAM
}
}
#[derive(Debug, Clone, Copy, Pod)]
#[repr(C)]
pub struct VirtioVsockConfig {
/// The guest_cid field contains the guests context ID, which uniquely identifies
/// the device for its lifetime. The upper 32 bits of the CID are reserved and zeroed.
///
/// According to virtio spec v1.1 2.4.1 Driver Requirements: Device Configuration Space,
/// drivers MUST NOT assume reads from fields greater than 32 bits wide are atomic.
/// So we need to split the u64 guest_cid into two parts.
pub guest_cid_low: u32,
pub guest_cid_high: u32,
}
impl PodOnce for VirtioVsockConfig {}
impl VirtioVsockConfig {
pub(crate) fn new(transport: &dyn VirtioTransport) -> SafePtr<Self, IoMem> {
let memory = transport.device_config_mem().unwrap();
SafePtr::new(memory, 0)
}
}