• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //! Implements virtio devices, queues, and transport mechanisms.
6 
7 mod balloon;
8 mod block;
9 #[cfg(feature = "gpu")]
10 mod gpu;
11 mod input;
12 mod net;
13 mod p9;
14 mod pmem;
15 mod queue;
16 mod rng;
17 #[cfg(feature = "tpm")]
18 mod tpm;
19 mod virtio_device;
20 mod virtio_pci_common_config;
21 mod virtio_pci_device;
22 mod wl;
23 
24 pub mod resource_bridge;
25 pub mod vhost;
26 
27 pub use self::balloon::*;
28 pub use self::block::*;
29 #[cfg(feature = "gpu")]
30 pub use self::gpu::*;
31 pub use self::input::*;
32 pub use self::net::*;
33 pub use self::p9::*;
34 pub use self::pmem::*;
35 pub use self::queue::*;
36 pub use self::rng::*;
37 #[cfg(feature = "tpm")]
38 pub use self::tpm::*;
39 pub use self::virtio_device::*;
40 pub use self::virtio_pci_device::*;
41 pub use self::wl::*;
42 
43 const DEVICE_ACKNOWLEDGE: u32 = 0x01;
44 const DEVICE_DRIVER: u32 = 0x02;
45 const DEVICE_DRIVER_OK: u32 = 0x04;
46 const DEVICE_FEATURES_OK: u32 = 0x08;
47 const DEVICE_FAILED: u32 = 0x80;
48 
49 // Types taken from linux/virtio_ids.h
50 const TYPE_NET: u32 = 1;
51 const TYPE_BLOCK: u32 = 2;
52 const TYPE_RNG: u32 = 4;
53 const TYPE_BALLOON: u32 = 5;
54 #[allow(dead_code)]
55 const TYPE_GPU: u32 = 16;
56 const TYPE_9P: u32 = 9;
57 const TYPE_INPUT: u32 = 18;
58 const TYPE_VSOCK: u32 = 19;
59 const TYPE_PMEM: u32 = 27;
60 // Additional types invented by crosvm
61 const TYPE_WL: u32 = 30;
62 #[cfg(feature = "tpm")]
63 const TYPE_TPM: u32 = 31;
64 
65 const VIRTIO_F_VERSION_1: u32 = 32;
66 
67 const INTERRUPT_STATUS_USED_RING: u32 = 0x1;
68 const INTERRUPT_STATUS_CONFIG_CHANGED: u32 = 0x2;
69 
70 /// Offset from the base MMIO address of a virtio device used by the guest to notify the device of
71 /// queue events.
72 pub const NOTIFY_REG_OFFSET: u32 = 0x50;
73 
74 /// Returns a string representation of the given virtio device type number.
type_to_str(type_: u32) -> Option<&'static str>75 pub fn type_to_str(type_: u32) -> Option<&'static str> {
76     Some(match type_ {
77         TYPE_NET => "net",
78         TYPE_BLOCK => "block",
79         TYPE_RNG => "rng",
80         TYPE_BALLOON => "balloon",
81         TYPE_GPU => "gpu",
82         TYPE_9P => "9p",
83         TYPE_VSOCK => "vsock",
84         TYPE_WL => "wl",
85         _ => return None,
86     })
87 }
88