|
1 |
| -# Crate Name |
| 1 | +# vfio-ioctls |
2 | 2 |
|
3 | 3 | ## Design
|
4 | 4 |
|
5 |
| -TODO: This section should have a high-level design of the crate. |
| 5 | +The [VFIO driver framework](https://www.kernel.org/doc/Documentation/vfio.txt) |
| 6 | +provides unified APIs for direct device access. It is an IOMMU/device-agnostic framework for |
| 7 | +exposing direct device access to user space in a secure, IOMMU-protected environment. |
| 8 | +This framework is used for multiple devices, such as GPUs, network adapters, and compute |
| 9 | +accelerators. With direct device access, virtual machines or user space applications have |
| 10 | +direct access to the physical device. |
6 | 11 |
|
7 |
| -Some questions that might help in writing this section: |
8 |
| -- What is the purpose of this crate? |
9 |
| -- What are the main components of the crate? How do they interact which each |
10 |
| - other? |
| 12 | +The VFIO framework is originally developed on Linux system, and later Microsoft HyperVisor |
| 13 | +technology provides a compatible implementation. Therefore the VFIO framework is supported |
| 14 | +by both Linux and Microsoft HyperVisor. |
| 15 | + |
| 16 | +The `vfio-ioctls` crate is a safe wrapper over the VFIO APIs. It provides three classes of structs: |
| 17 | +- `VfioContainer`: a safe wrapper over a VFIO container object, and acts a container object |
| 18 | + to associate `VfioDevice` objects with IOMMU domains. |
| 19 | +- `VfioDevice`: a wrapper over a VFIO device object, provide methods to access the underlying |
| 20 | + hardware device. |
| 21 | +- `VfioIrq/VfioRegion`: describes capabilities/resources about a `VfioDevice` object. |
11 | 22 |
|
12 | 23 | ## Usage
|
13 | 24 |
|
14 |
| -TODO: This section describes how the crate is used. |
| 25 | +The `vfio-ioctls` crate may be used to support following usage scenarios: |
| 26 | +- Direct device assignment to virtual machine based on Linux KVM, with default features. |
| 27 | +- Direct device assignment to virtual machine based on Microsoft HyperVisor, with `--no-default-features --features=mshv`. |
| 28 | +- User mode device drivers, with `--no-default-features`. |
| 29 | + |
| 30 | +First, add the following to your Cargo.toml: |
| 31 | +```toml |
| 32 | +vfio-ioctls = "0.1" |
| 33 | +``` |
| 34 | +Next, add this to your crate root: |
| 35 | + |
| 36 | +```rust |
| 37 | +extern crate vfio_ioctls; |
| 38 | +``` |
| 39 | + |
| 40 | +By default vfio-ioctls has the `kvm` feature enabled. You may turn off the default features by |
| 41 | +`default-features = false`. To enable feature `mshv`, |
| 42 | +```toml |
| 43 | +vfio-ioctls = { version = "0.1", default-features = false, features = ["mshv"]} |
| 44 | +``` |
15 | 45 |
|
16 |
| -Some questions that might help in writing this section: |
17 |
| -- What traits do users need to implement? |
18 |
| -- Does the crate have any default/optional features? What is each feature |
19 |
| - doing? |
20 |
| -- Is this crate used by other rust-vmm components? If yes, how? |
21 | 46 |
|
22 | 47 | ## Examples
|
23 | 48 |
|
24 |
| -TODO: Usage examples. |
| 49 | +To create VFIO device object for user mode drivers, |
25 | 50 |
|
26 | 51 | ```rust
|
27 |
| -use my_crate; |
| 52 | +use std::sync::Arc; |
| 53 | +use vfio_ioctls::{VfioContainer, VfioDevice}; |
| 54 | + |
| 55 | +fn create_vfio_device() { |
| 56 | + // TODO: change to your device's path |
| 57 | + let device_path = "/sys/bus/pci/devices/00:03.0"; |
| 58 | + let vfio_container = Arc::new(VfioContainer::new(()).unwrap()); |
| 59 | + let vfio_dev = VfioDevice::new(&Path::new(device_path), vfio_container.clone()).unwrap(); |
| 60 | + let irqs = vfio_dev.max_interrupts(); |
28 | 61 |
|
29 |
| -... |
| 62 | + assert!(irqs > 0); |
| 63 | +} |
30 | 64 | ```
|
31 | 65 |
|
32 | 66 | ## License
|
33 | 67 |
|
34 |
| -**!!!NOTICE**: The BSD-3-Clause license is not included in this template. |
35 |
| -The license needs to be manually added because the text of the license file |
36 |
| -also includes the copyright. The copyright can be different for different |
37 |
| -crates. If the crate contains code from CrosVM, the crate must add the |
38 |
| -CrosVM copyright which can be found |
39 |
| -[here](https://chromium.googlesource.com/chromiumos/platform/crosvm/+/master/LICENSE). |
40 |
| -For crates developed from scratch, the copyright is different and depends on |
41 |
| -the contributors. |
| 68 | +This code is licensed under Apache-2.0 or BSD-3-Clause. |
0 commit comments