summaryrefslogtreecommitdiffstats
path: root/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs
diff options
context:
space:
mode:
authorMichele Paolino <m.paolino@virtualopensystems.com>2023-12-18 13:48:17 +0000
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2023-12-29 15:58:49 +0000
commit5ea74929e0cc276eda3f69737097c0903d771e95 (patch)
tree74d9c2881301e0c59561a6a8fc2bda3ed8a83123 /meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs
parentfd0411d38d889b74958bcb6e461c80f65133d737 (diff)
Vhost-user-console device and can license fixes
This patch presents a new console device and fixes vhost-user-can license. vhost-device can and conosle devices will be proposed to rust-vmm/vhost-device community, and in case of acceptace this patch will be updated. Bug-AGL: SPEC-4834 Change-Id: I4dcded8733195158f848bd0e4fd4f4618a378c3a Signed-off-by: Michele Paolino <m.paolino@virtualopensystems.com>
Diffstat (limited to 'meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs')
-rw-r--r--meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs86
1 files changed, 86 insertions, 0 deletions
diff --git a/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs b/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs
new file mode 100644
index 00000000..2e2972b2
--- /dev/null
+++ b/meta-egvirt/recipes-extended/vhost-device-console/vhost-device-console-0.1.0/src/console.rs
@@ -0,0 +1,86 @@
+// CAN backend device
+//
+// Copyright 2023 VIRTUAL OPEN SYSTEMS SAS. All Rights Reserved.
+// Timos Ampelikiotis <t.ampelikiotis@virtualopensystems.com>
+//
+// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
+
+use log::{warn, error};
+use std::sync::{Arc, RwLock};
+
+use thiserror::Error as ThisError;
+use vm_memory::{ByteValued, Le16};
+
+use crate::vhu_console::{VirtioConsoleConfig, VirtioConsoleControl};
+
+type Result<T> = std::result::Result<T, Error>;
+
+#[derive(Copy, Clone, Debug, PartialEq, ThisError)]
+pub(crate) enum Error {
+ #[error("Console not enabled yet")]
+ ConsoleNotEnabled,
+}
+
+#[derive(Debug)]
+pub(crate) struct ConsoleController {
+ config: VirtioConsoleConfig,
+ pub console_name: String,
+}
+
+impl ConsoleController {
+ // Creates a new controller corresponding to `device`.
+ pub(crate) fn new(console_name: String) -> Result<ConsoleController> {
+
+ let console_name = console_name.to_owned();
+ println!("console_name: {:?}", console_name);
+
+ Ok(ConsoleController {
+ config: VirtioConsoleConfig {
+ cols: 20.into(),
+ rows: 20.into(),
+ max_nr_ports: 1.into(),
+ emerg_wr: 64.into(),
+ },
+ console_name,
+ })
+ }
+
+ pub(crate) fn config(&self) -> &VirtioConsoleConfig {
+ log::trace!("Get config\n");
+ &self.config
+ }
+
+ pub(crate) fn operation(&self, tx_request: VirtioConsoleControl) -> Result<()> {
+ log::trace!("Console operation\n");
+ Ok(())
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_new_console_controller() {
+ let console_name = String::from("test_console");
+ let controller = ConsoleController::new(console_name.clone());
+
+ assert!(controller.is_ok());
+
+ let controller = controller.unwrap();
+ assert_eq!(controller.console_name, "test_console");
+ }
+
+ #[test]
+ fn test_console_controller_config() {
+ let console_name = String::from("test_console");
+ let controller = ConsoleController::new(console_name).unwrap();
+
+ let config = controller.config();
+ assert_eq!(config.cols, 20);
+ assert_eq!(config.rows, 20);
+ assert_eq!(config.max_nr_ports, 1);
+ assert_eq!(config.emerg_wr, 64);
+ }
+}
+