• 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 
15 #[cfg(feature = "audio")]
parse_ac97_options( _ac97_params: &mut devices::Ac97Parameters, key: &str, _value: &str, ) -> Result<(), String>16 pub fn parse_ac97_options(
17     _ac97_params: &mut devices::Ac97Parameters,
18     key: &str,
19     _value: &str,
20 ) -> Result<(), String> {
21     Err(format!("unknown ac97 parameter {}", key))
22 }
23 
check_serial_params( #[allow(unused_variables)] serial_params: &SerialParameters, ) -> Result<(), String>24 pub fn check_serial_params(
25     #[allow(unused_variables)] serial_params: &SerialParameters,
26 ) -> Result<(), String> {
27     #[cfg(feature = "prod-build")]
28     {
29         if matches!(serial_params.type_, SerialType::SystemSerialType) {
30             return Err(format!(
31                 "device type not supported: {}",
32                 serial_params.type_.to_string()
33             ));
34         }
35         if serial_params.stdin {
36             return Err(format!("parameter not supported: stdin"));
37         }
38     }
39     Ok(())
40 }
41 
validate_config(_cfg: &mut Config) -> std::result::Result<(), String>42 pub fn validate_config(_cfg: &mut Config) -> std::result::Result<(), String> {
43     Ok(())
44 }
45 
46 #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
47 pub enum IrqChipKind {
48     /// All interrupt controllers are emulated in the kernel.
49     Kernel,
50     /// APIC is emulated in the kernel.  All other interrupt controllers are in userspace.
51     Split,
52     /// All interrupt controllers are emulated in userspace.
53     Userspace,
54 }
55 
56 impl FromStr for IrqChipKind {
57     type Err = &'static str;
58 
from_str(s: &str) -> Result<Self, Self::Err>59     fn from_str(s: &str) -> Result<Self, Self::Err> {
60         match s.to_lowercase().as_str() {
61             "kernel" => Ok(Self::Kernel),
62             "split" => Ok(Self::Split),
63             "userspace" => Ok(Self::Userspace),
64             _ => Err("invalid irqchip kind: expected \"kernel\", \"split\", or \"userspace\""),
65         }
66     }
67 }
68 
69 /// Hypervisor backend.
70 #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, Eq)]
71 pub enum HypervisorKind {
72     #[cfg(feature = "gvm")]
73     Gvm,
74     #[cfg(feature = "haxm")]
75     Haxm,
76     #[cfg(feature = "haxm")]
77     Ghaxm,
78     #[cfg(feature = "whpx")]
79     Whpx,
80 }
81 
82 impl FromStr for HypervisorKind {
83     type Err = &'static str;
84 
from_str(s: &str) -> Result<Self, Self::Err>85     fn from_str(s: &str) -> Result<Self, Self::Err> {
86         match s.to_lowercase().as_str() {
87             #[cfg(feature = "gvm")]
88             "gvm" => Ok(HypervisorKind::Gvm),
89             #[cfg(feature = "haxm")]
90             "haxm" => Ok(HypervisorKind::Haxm),
91             #[cfg(feature = "haxm")]
92             "ghaxm" => Ok(HypervisorKind::Ghaxm),
93             #[cfg(feature = "whpx")]
94             "whpx" => Ok(HypervisorKind::Whpx),
95             _ => Err("invalid hypervisor backend"),
96         }
97     }
98 }
99 
100 #[cfg(test)]
101 mod tests {
102     #[cfg(feature = "audio")]
103     #[test]
parse_ac97_vaild()104     fn parse_ac97_vaild() {
105         crate::crosvm::config::parse_ac97_options("backend=win_audio")
106             .expect("parse should have succeded");
107     }
108 }
109