|
| 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