-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from syswonder/virtio_console
Add Virtio-console
- Loading branch information
Showing
28 changed files
with
513 additions
and
63 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ FEATURES ?= | |
APP_FEATURES ?= | ||
|
||
# QEMU options | ||
CONSOLE ?= n | ||
BLK ?= n | ||
NET ?= n | ||
GRAPHIC ?= n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "driver_console" | ||
version = "0.1.0" | ||
edition = "2021" | ||
authors = [ | ||
"Hangqi Ren <[email protected]>" | ||
] | ||
description = "Common traits and types for console drivers" | ||
license = "GPL-3.0-or-later OR Apache-2.0" | ||
homepage = "https://github.com/syswonder/ruxos" | ||
repository = "https://github.com/syswonder/ruxos/tree/main/crates/driver_console" | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[features] | ||
default = [] | ||
|
||
[dependencies] | ||
driver_common = { path = "../driver_common" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* Copyright (c) [2023] [Syswonder Community] | ||
* [Ruxos] is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
//! Common traits and types for block storage device drivers (i.e. disk). | ||
|
||
#![no_std] | ||
#![feature(doc_auto_cfg)] | ||
#![feature(const_trait_impl)] | ||
|
||
#[doc(no_inline)] | ||
pub use driver_common::{BaseDriverOps, DevError, DevResult, DeviceType}; | ||
|
||
/// Operations that require a console device driver to implement. | ||
pub trait ConsoleDriverOps: BaseDriverOps { | ||
/// Writes a single byte to the console. | ||
fn putchar(&mut self, c: u8); | ||
/// Reads a single byte from the console. | ||
fn getchar(&mut self) -> Option<u8>; | ||
/// Acknowledge an interrupt from the console. | ||
fn ack_interrupt(&mut self) -> DevResult<bool>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* Copyright (c) [2023] [Syswonder Community] | ||
* [Ruxos] is licensed under Mulan PSL v2. | ||
* You can use this software according to the terms and conditions of the Mulan PSL v2. | ||
* You may obtain a copy of Mulan PSL v2 at: | ||
* http://license.coscl.org.cn/MulanPSL2 | ||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. | ||
* See the Mulan PSL v2 for more details. | ||
*/ | ||
|
||
use crate::as_dev_err; | ||
use driver_common::{BaseDriverOps, DevResult, DeviceType}; | ||
use driver_console::ConsoleDriverOps; | ||
use virtio_drivers::{device::console::VirtIOConsole as InnerDev, transport::Transport, Hal}; | ||
|
||
/// VirtIO console device | ||
pub struct VirtIoConsoleDev<H: Hal, T: Transport> { | ||
inner: InnerDev<'static, H, T>, | ||
} | ||
|
||
unsafe impl<H: Hal, T: Transport> Send for VirtIoConsoleDev<H, T> {} | ||
unsafe impl<H: Hal, T: Transport> Sync for VirtIoConsoleDev<H, T> {} | ||
|
||
impl<H: Hal, T: Transport> VirtIoConsoleDev<H, T> { | ||
/// Creates a new driver instance and initializes the device, or returns | ||
/// an error if any step fails. | ||
pub fn try_new(transport: T) -> DevResult<Self> { | ||
Ok(Self { | ||
inner: InnerDev::new(transport).map_err(as_dev_err)?, | ||
}) | ||
} | ||
} | ||
|
||
impl<H: Hal, T: Transport> BaseDriverOps for VirtIoConsoleDev<H, T> { | ||
fn device_name(&self) -> &str { | ||
"virtio-console" | ||
} | ||
|
||
fn device_type(&self) -> DeviceType { | ||
DeviceType::Char | ||
} | ||
} | ||
|
||
impl<H: Hal, T: Transport> ConsoleDriverOps for VirtIoConsoleDev<H, T> { | ||
fn putchar(&mut self, c: u8) { | ||
self.inner | ||
.send(c) | ||
.expect("VirtConsole: failed to send char"); | ||
} | ||
|
||
fn getchar(&mut self) -> Option<u8> { | ||
self.inner | ||
.recv(true) | ||
.expect("VirtConsole: failed to recv char") | ||
} | ||
|
||
fn ack_interrupt(&mut self) -> DevResult<bool> { | ||
self.inner.ack_interrupt().map_err(as_dev_err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.