2019-04-18 17:24:06 +00:00
|
|
|
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
2019-05-08 10:22:53 +00:00
|
|
|
// found in the LICENSE-BSD-3-Clause file.
|
|
|
|
//
|
|
|
|
// Copyright © 2019 Intel Corporation
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
2019-04-18 17:24:06 +00:00
|
|
|
|
2020-07-02 12:25:19 +00:00
|
|
|
//! Implements virtio queues
|
2019-12-31 10:49:11 +00:00
|
|
|
|
2019-04-18 17:24:06 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2020-04-08 01:53:12 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2019-04-18 17:24:06 +00:00
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
|
2020-02-21 10:34:51 +00:00
|
|
|
pub mod queue;
|
2020-07-02 12:25:19 +00:00
|
|
|
pub use queue::*;
|
2019-04-18 17:24:06 +00:00
|
|
|
|
2020-07-02 12:25:19 +00:00
|
|
|
pub type VirtioIommuRemapping =
|
|
|
|
Box<dyn Fn(u64) -> std::result::Result<u64, std::io::Error> + Send + Sync>;
|
2019-04-18 17:24:06 +00:00
|
|
|
|
|
|
|
// Types taken from linux/virtio_ids.h
|
2020-04-27 14:55:52 +00:00
|
|
|
#[derive(Copy, Clone, Debug)]
|
2019-04-18 17:24:06 +00:00
|
|
|
#[allow(dead_code)]
|
|
|
|
#[allow(non_camel_case_types)]
|
|
|
|
#[repr(C)]
|
2020-04-27 14:55:52 +00:00
|
|
|
pub enum VirtioDeviceType {
|
2019-04-18 17:24:06 +00:00
|
|
|
TYPE_NET = 1,
|
|
|
|
TYPE_BLOCK = 2,
|
2019-07-22 18:50:56 +00:00
|
|
|
TYPE_CONSOLE = 3,
|
2019-04-18 17:24:06 +00:00
|
|
|
TYPE_RNG = 4,
|
|
|
|
TYPE_BALLOON = 5,
|
|
|
|
TYPE_9P = 9,
|
|
|
|
TYPE_GPU = 16,
|
|
|
|
TYPE_INPUT = 18,
|
|
|
|
TYPE_VSOCK = 19,
|
2019-09-17 18:40:14 +00:00
|
|
|
TYPE_IOMMU = 23,
|
2020-03-04 02:12:22 +00:00
|
|
|
TYPE_MEM = 24,
|
2019-05-21 18:54:53 +00:00
|
|
|
TYPE_FS = 26,
|
2019-06-18 21:40:57 +00:00
|
|
|
TYPE_PMEM = 27,
|
2019-07-02 15:11:09 +00:00
|
|
|
TYPE_UNKNOWN = 0xFF,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<u32> for VirtioDeviceType {
|
|
|
|
fn from(t: u32) -> Self {
|
|
|
|
match t {
|
|
|
|
1 => VirtioDeviceType::TYPE_NET,
|
|
|
|
2 => VirtioDeviceType::TYPE_BLOCK,
|
2020-01-09 13:50:15 +00:00
|
|
|
3 => VirtioDeviceType::TYPE_CONSOLE,
|
2019-07-02 15:11:09 +00:00
|
|
|
4 => VirtioDeviceType::TYPE_RNG,
|
|
|
|
5 => VirtioDeviceType::TYPE_BALLOON,
|
|
|
|
9 => VirtioDeviceType::TYPE_9P,
|
|
|
|
16 => VirtioDeviceType::TYPE_GPU,
|
|
|
|
18 => VirtioDeviceType::TYPE_INPUT,
|
|
|
|
19 => VirtioDeviceType::TYPE_VSOCK,
|
2019-09-17 18:40:14 +00:00
|
|
|
23 => VirtioDeviceType::TYPE_IOMMU,
|
2020-03-04 02:12:22 +00:00
|
|
|
24 => VirtioDeviceType::TYPE_MEM,
|
2019-07-02 15:11:09 +00:00
|
|
|
26 => VirtioDeviceType::TYPE_FS,
|
|
|
|
27 => VirtioDeviceType::TYPE_PMEM,
|
|
|
|
_ => VirtioDeviceType::TYPE_UNKNOWN,
|
|
|
|
}
|
|
|
|
}
|
2019-04-18 17:24:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// In order to use the `{}` marker, the trait `fmt::Display` must be implemented
|
|
|
|
// manually for the type VirtioDeviceType.
|
|
|
|
impl fmt::Display for VirtioDeviceType {
|
|
|
|
// This trait requires `fmt` with this exact signature.
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let output = match *self {
|
|
|
|
VirtioDeviceType::TYPE_NET => "net",
|
|
|
|
VirtioDeviceType::TYPE_BLOCK => "block",
|
2020-01-09 13:50:15 +00:00
|
|
|
VirtioDeviceType::TYPE_CONSOLE => "console",
|
2019-04-18 17:24:06 +00:00
|
|
|
VirtioDeviceType::TYPE_RNG => "rng",
|
|
|
|
VirtioDeviceType::TYPE_BALLOON => "balloon",
|
|
|
|
VirtioDeviceType::TYPE_GPU => "gpu",
|
|
|
|
VirtioDeviceType::TYPE_9P => "9p",
|
2020-01-09 13:50:15 +00:00
|
|
|
VirtioDeviceType::TYPE_INPUT => "input",
|
2019-04-18 17:24:06 +00:00
|
|
|
VirtioDeviceType::TYPE_VSOCK => "vsock",
|
2020-01-09 13:50:15 +00:00
|
|
|
VirtioDeviceType::TYPE_IOMMU => "iommu",
|
2020-03-04 02:12:22 +00:00
|
|
|
VirtioDeviceType::TYPE_MEM => "mem",
|
2019-05-21 18:54:53 +00:00
|
|
|
VirtioDeviceType::TYPE_FS => "fs",
|
2019-06-18 21:40:57 +00:00
|
|
|
VirtioDeviceType::TYPE_PMEM => "pmem",
|
2020-01-09 13:50:15 +00:00
|
|
|
VirtioDeviceType::TYPE_UNKNOWN => "UNKNOWN",
|
2019-04-18 17:24:06 +00:00
|
|
|
};
|
|
|
|
write!(f, "{}", output)
|
|
|
|
}
|
|
|
|
}
|