• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use std::str::FromStr;
6 
7 #[cfg(feature = "prod-build")]
8 use devices::serial_device::SerialType;
9 use devices::SerialParameters;
10 use serde::Deserialize;
11 use serde::Serialize;
12 
13 use crate::crosvm::config::Config;
14 
check_serial_params( #[allow(unused_variables)] serial_params: &SerialParameters, ) -> Result<(), String>15 pub fn check_serial_params(
16     #[allow(unused_variables)] serial_params: &SerialParameters,
17 ) -> Result<(), String> {
18     #[cfg(feature = "prod-build")]
19     {
20         if matches!(serial_params.type_, SerialType::SystemSerialType) {
21             return Err(format!(
22                 "device type not supported: {}",
23                 serial_params.type_.to_string()
24             ));
25         }
26         if serial_params.stdin {
27             return Err(format!("parameter not supported: stdin"));
28         }
29     }
30     Ok(())
31 }
32 
validate_config(_cfg: &mut Config) -> std::result::Result<(), String>33 pub fn validate_config(_cfg: &mut Config) -> std::result::Result<(), String> {
34     Ok(())
35 }
36 
37 /// Hypervisor backend.
38 #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq)]
39 pub enum HypervisorKind {
40     #[cfg(feature = "gvm")]
41     Gvm,
42     #[cfg(feature = "haxm")]
43     Haxm,
44     #[cfg(feature = "haxm")]
45     Ghaxm,
46     #[cfg(feature = "whpx")]
47     Whpx,
48 }
49 
50 impl FromStr for HypervisorKind {
51     type Err = &'static str;
52 
from_str(s: &str) -> Result<Self, Self::Err>53     fn from_str(s: &str) -> Result<Self, Self::Err> {
54         match s.to_lowercase().as_str() {
55             #[cfg(feature = "gvm")]
56             "gvm" => Ok(HypervisorKind::Gvm),
57             #[cfg(feature = "haxm")]
58             "haxm" => Ok(HypervisorKind::Haxm),
59             #[cfg(feature = "haxm")]
60             "ghaxm" => Ok(HypervisorKind::Ghaxm),
61             #[cfg(feature = "whpx")]
62             "whpx" => Ok(HypervisorKind::Whpx),
63             _ => Err("invalid hypervisor backend"),
64         }
65     }
66 }
67