Skip to content

Commit 90b44fb

Browse files
committed
add support of console
Add structs and constants, which are derived from the specification Virtual I/O Device (VIRTIO), Version 1.2
1 parent 5fa844e commit 90b44fb

File tree

5 files changed

+132
-24
lines changed

5 files changed

+132
-24
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "virtio-spec"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
authors = ["Martin Kröning <[email protected]>"]
55
edition = "2021"
66
description = "Definitions from the Virtual I/O Device (VIRTIO) specification."

src/console.rs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//! Console Device
2+
3+
use volatile::access::ReadOnly;
4+
use volatile_macro::VolatileFieldAccess;
5+
6+
pub use super::features::console::F;
7+
use crate::{le16, le32};
8+
9+
/// Conspole Device Configuration Layout
10+
///
11+
/// Use [`ConfigVolatileFieldAccess`] to work with this struct.
12+
#[doc(alias = "virtio_console_config")]
13+
#[cfg_attr(
14+
feature = "zerocopy",
15+
derive(
16+
zerocopy_derive::KnownLayout,
17+
zerocopy_derive::Immutable,
18+
zerocopy_derive::FromBytes,
19+
)
20+
)]
21+
#[derive(VolatileFieldAccess)]
22+
#[repr(C)]
23+
pub struct Config {
24+
#[access(ReadOnly)]
25+
cols: le16,
26+
#[access(ReadOnly)]
27+
rows: le16,
28+
#[access(ReadOnly)]
29+
max_nr_ports: le16,
30+
#[access(ReadOnly)]
31+
emerg_wr: le32,
32+
}
33+
34+
/// The layout of the console control message
35+
#[doc(alias = "virtio_console_control")]
36+
#[cfg_attr(
37+
feature = "zerocopy",
38+
derive(
39+
zerocopy_derive::KnownLayout,
40+
zerocopy_derive::Immutable,
41+
zerocopy_derive::FromBytes,
42+
zerocopy_derive::IntoBytes,
43+
)
44+
)]
45+
#[derive(Clone, Copy, Debug)]
46+
#[repr(C)]
47+
pub struct ConsoleControl {
48+
/// Port number
49+
pub id: le32,
50+
/// The kind of control event
51+
pub event: Event,
52+
/// Extra information for the event
53+
pub value: le16,
54+
}
55+
56+
endian_bitflags! {
57+
#[doc(alias = "VIRTIO_CONSOLE")]
58+
pub struct Event: le16 {
59+
#[doc(alias = "VIRTIO_CONSOLE_DEVICE_READY")]
60+
const DEVICE_READY = 0;
61+
62+
#[doc(alias = "VIRTIO_CONSOLE_DEVICE_ADD")]
63+
const DEVICE_ADD = 1;
64+
65+
#[doc(alias = "VIRTIO_CONSOLE_DEVICE_REMOVE")]
66+
const DEVICE_REMOVE = 2;
67+
68+
#[doc(alias = "VIRTIO_CONSOLE_PORT_READY")]
69+
const PORT_READY = 3;
70+
71+
#[doc(alias = "VIRTIO_CONSOLE_CONSOLE_PORT")]
72+
const CONSOLE_PORT = 4;
73+
74+
#[doc(alias = "VIRTIO_CONSOLE_RESIZE")]
75+
const CONSOLE_RESIZE = 5;
76+
77+
#[doc(alias = "VIRTIO_CONSOLE_PORT_OPEN")]
78+
const PORT_OPEN = 6;
79+
80+
#[doc(alias = "VIRTIO_CONSOLE_PORT_NAME")]
81+
const PORT_NAME = 7;
82+
}
83+
}

src/features.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,30 @@ macro_rules! feature_bits {
289289
() => {};
290290
}
291291

292+
pub mod console {
293+
use crate::le128;
294+
295+
feature_bits! {
296+
/// Console Device Feature Bits
297+
#[doc(alias = "VIRTIO_CONSOLE_F")]
298+
pub struct F: le128 {
299+
/// Configuration cols and rows are valid.
300+
#[doc(alias = "VIRTIO_CONSOLE_F_SIZE")]
301+
const SIZE = 1 << 0;
302+
303+
/// Device has support for multiple ports; max_nr_ports is valid and control virtqueues will be used.
304+
#[doc(alias = "VIRTIO_CONSOLE_F_MULTIPORT")]
305+
const MULTIPORT = 1 << 1;
306+
307+
/// Device has support for emergency write. Configuration field emerg_wr is valid.
308+
#[doc(alias = "VIRTIO_CONSOLE_F_EMERG_WRITE")]
309+
const EMERG_WRITE = 1 << 2;
310+
}
311+
}
312+
313+
impl crate::FeatureBits for F {}
314+
}
315+
292316
pub mod net {
293317
use crate::le128;
294318

src/lib.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,27 +61,27 @@
6161
//!
6262
//! ## Device Types
6363
//!
64-
//! | Device Type | Available | Module |
65-
//! | --------------------------------- | --------- | --------- |
66-
//! | Network Device | ✅ | [`net`] |
67-
//! | Block Device | ❌ | |
68-
//! | Console Device | | |
69-
//! | Entropy Device | ❌ | |
70-
//! | Traditional Memory Balloon Device | ❌ | |
71-
//! | SCSI Host Device | ❌ | |
72-
//! | GPU Device | ❌ | |
73-
//! | Input Device | ❌ | |
74-
//! | Crypto Device | ❌ | |
75-
//! | Socket Device | ✅ | [`vsock`] |
76-
//! | File System Device | ✅ | [`fs`] |
77-
//! | RPMB Device | ❌ | |
78-
//! | IOMMU Device | ❌ | |
79-
//! | Sound Device | ❌ | |
80-
//! | Memory Device | ❌ | |
81-
//! | I2C Adapter Device | ❌ | |
82-
//! | SCMI Device | ❌ | |
83-
//! | GPIO Device | ❌ | |
84-
//! | PMEM Device | ❌ | |
64+
//! | Device Type | Available | Module |
65+
//! | --------------------------------- | --------- | ----------- |
66+
//! | Network Device | ✅ | [`net`] |
67+
//! | Block Device | ❌ | |
68+
//! | Console Device | | [`console`] |
69+
//! | Entropy Device | ❌ | |
70+
//! | Traditional Memory Balloon Device | ❌ | |
71+
//! | SCSI Host Device | ❌ | |
72+
//! | GPU Device | ❌ | |
73+
//! | Input Device | ❌ | |
74+
//! | Crypto Device | ❌ | |
75+
//! | Socket Device | ✅ | [`vsock`] |
76+
//! | File System Device | ✅ | [`fs`] |
77+
//! | RPMB Device | ❌ | |
78+
//! | IOMMU Device | ❌ | |
79+
//! | Sound Device | ❌ | |
80+
//! | Memory Device | ❌ | |
81+
//! | I2C Adapter Device | ❌ | |
82+
//! | SCMI Device | ❌ | |
83+
//! | GPIO Device | ❌ | |
84+
//! | PMEM Device | ❌ | |
8585
8686
#![cfg_attr(not(test), no_std)]
8787
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
@@ -94,6 +94,7 @@ extern crate alloc;
9494
mod bitflags;
9595
#[macro_use]
9696
pub mod volatile;
97+
pub mod console;
9798
#[cfg(any(feature = "mmio", feature = "pci"))]
9899
mod driver_notifications;
99100
mod features;

0 commit comments

Comments
 (0)