Skip to content

Commit 8884465

Browse files
stefano-garzarellajiangliu
authored andcommitted
Add VhostVdpa trait
Add new VhostVdpa trait to handle vhost-vdpa devices and a new vhost-vdpa building feature. vhost-vdpa devices is based on vhost backend, for this reason VhostVdpa trait requires VhostBackend. Signed-off-by: Stefano Garzarella <[email protected]>
1 parent 7b70a12 commit 8884465

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ edition = "2018"
1414
default = []
1515
vhost-vsock = []
1616
vhost-kern = []
17+
vhost-vdpa = ["vhost-kern"]
1718
vhost-user = []
1819
vhost-user-master = ["vhost-user"]
1920
vhost-user-slave = ["vhost-user"]

coverage_config_x86_64.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"coverage_score": 80.8, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"}
1+
{"coverage_score": 80.2, "exclude_path": "src/vhost_kern/", "crate_features": "vhost-user-master,vhost-user-slave"}

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ extern crate vmm_sys_util;
4040
mod backend;
4141
pub use backend::*;
4242

43+
#[cfg(feature = "vhost-vdpa")]
44+
pub mod vdpa;
4345
#[cfg(feature = "vhost-kern")]
4446
pub mod vhost_kern;
4547
#[cfg(feature = "vhost-user")]

src/vdpa.rs

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (C) 2021 Red Hat, Inc. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
3+
4+
//! Trait to control vhost-vdpa backend drivers.
5+
6+
use vmm_sys_util::eventfd::EventFd;
7+
8+
use crate::backend::VhostBackend;
9+
use crate::Result;
10+
11+
/// vhost vdpa IOVA range
12+
pub struct VhostVdpaIovaRange {
13+
/// First address that can be mapped by vhost-vDPA.
14+
pub first: u64,
15+
/// Last address that can be mapped by vhost-vDPA.
16+
pub last: u64,
17+
}
18+
19+
/// Trait to control vhost-vdpa backend drivers.
20+
pub trait VhostVdpa: VhostBackend {
21+
/// Get the device id.
22+
/// The device ids follow the same definition of the device id defined in virtio-spec.
23+
fn get_device_id(&self) -> Result<u32>;
24+
25+
/// Get the status.
26+
/// The status bits follow the same definition of the device status defined in virtio-spec.
27+
fn get_status(&self) -> Result<u8>;
28+
29+
/// Set the status.
30+
/// The status bits follow the same definition of the device status defined in virtio-spec.
31+
///
32+
/// # Arguments
33+
/// * `status` - Status bits to set
34+
fn set_status(&self, status: u8) -> Result<()>;
35+
36+
/// Get the device configuration.
37+
///
38+
/// # Arguments
39+
/// * `offset` - Offset in the device configuration space
40+
/// * `buffer` - Buffer for configuration data
41+
fn get_config(&self, offset: u32, buffer: &mut [u8]) -> Result<()>;
42+
43+
/// Set the device configuration.
44+
///
45+
/// # Arguments
46+
/// * `offset` - Offset in the device configuration space
47+
/// * `buffer` - Buffer for configuration data
48+
fn set_config(&self, offset: u32, buffer: &[u8]) -> Result<()>;
49+
50+
/// Set the status for a given vring.
51+
///
52+
/// # Arguments
53+
/// * `queue_index` - Index of the queue to enable/disable.
54+
/// * `enabled` - true to enable the vring, false to disable it.
55+
fn set_vring_enable(&self, queue_index: usize, enabled: bool) -> Result<()>;
56+
57+
/// Get the maximum number of descriptors in the vring supported by the device.
58+
fn get_vring_num(&self) -> Result<u16>;
59+
60+
/// Set the eventfd to trigger when device configuration change.
61+
///
62+
/// # Arguments
63+
/// * `fd` - EventFd to trigger.
64+
fn set_config_call(&self, fd: &EventFd) -> Result<()>;
65+
66+
/// Get the valid I/O virtual addresses range supported by the device.
67+
fn get_iova_range(&self) -> Result<VhostVdpaIovaRange>;
68+
}

0 commit comments

Comments
 (0)