virtio_spec/console.rs
1//! Console Device
2
3use num_enum::{IntoPrimitive, TryFromPrimitive};
4use volatile::access::ReadOnly;
5use volatile_macro::VolatileFieldAccess;
6
7pub use super::features::console::F;
8use crate::{le16, le32};
9
10/// Console Device Configuration Layout
11///
12/// Use [`ConfigVolatileFieldAccess`] to work with this struct.
13#[doc(alias = "virtio_console_config")]
14#[derive(VolatileFieldAccess)]
15#[repr(C)]
16pub struct Config {
17 #[access(ReadOnly)]
18 cols: le16,
19 #[access(ReadOnly)]
20 rows: le16,
21 #[access(ReadOnly)]
22 max_nr_ports: le32,
23 #[access(ReadOnly)]
24 emerg_wr: le32,
25}
26
27/// Control Message
28#[doc(alias = "virtio_console_control")]
29#[cfg_attr(
30 feature = "zerocopy",
31 derive(
32 zerocopy_derive::KnownLayout,
33 zerocopy_derive::Immutable,
34 zerocopy_derive::FromBytes,
35 zerocopy_derive::IntoBytes,
36 )
37)]
38#[derive(Clone, Copy, Debug)]
39#[repr(C)]
40pub struct Control {
41 /// Port number
42 pub id: le32,
43 /// The kind of control event
44 pub event: le16,
45 /// Extra information for the event
46 pub value: le16,
47}
48
49/// Event
50#[doc(alias = "VIRTIO_CONSOLE")]
51#[derive(IntoPrimitive, TryFromPrimitive, PartialEq, Eq, Clone, Copy, Debug)]
52#[non_exhaustive]
53#[repr(u16)]
54pub enum Device {
55 /// Sent by the driver at initialization to indicate that it is ready to receive control messages.
56 ///
57 /// A value of 1 indicates success, and 0 indicates failure.
58 /// The port number `id` is unused.
59 #[doc(alias = "VIRTIO_CONSOLE_DEVICE_READY")]
60 DeviceReady = 0,
61
62 /// Sent by the device, to create a new port.
63 ///
64 /// `value` is unused.
65 #[doc(alias = "VIRTIO_CONSOLE_DEVICE_ADD")]
66 DeviceAdd = 1,
67
68 /// Sent by the device, to remove an existing port.
69 ///
70 /// `value` is unused.
71 #[doc(alias = "VIRTIO_CONSOLE_DEVICE_REMOVE")]
72 DeviceRemove = 2,
73
74 /// Sent by the driver in response to the device's VIRTIO_CONSOLE_PORT_ADD message, to indicate that the port is ready to be used.
75 ///
76 /// A `value` of 1 indicates success, and 0 indicates failure.
77 #[doc(alias = "VIRTIO_CONSOLE_PORT_READY")]
78 PortReady = 3,
79
80 /// Sent by the device to nominate a port as a console port.
81 ///
82 /// There MAY be more than one console port.
83 #[doc(alias = "VIRTIO_CONSOLE_CONSOLE_PORT")]
84 ConsolePort = 4,
85
86 /// Sent by the device to indicate a console size change.
87 ///
88 /// `value` is unused.
89 /// The buffer is followed by the number of columns and rows ([`virtio_console_resize`]).
90 ///
91 /// [`virtio_console_resize`]: Resize
92 #[doc(alias = "VIRTIO_CONSOLE_RESIZE")]
93 Resize = 5,
94
95 /// This message is sent by both the device and the driver.
96 ///
97 /// `value` indicates the state: 0 (port closed) or 1 (port open).
98 /// This allows for ports to be used directly by guest and host processes to communicate in an application-defined manner.
99 #[doc(alias = "VIRTIO_CONSOLE_PORT_OPEN")]
100 PortOpen = 6,
101
102 /// Sent by the device to give a tag to the port.
103 ///
104 /// This control command is immediately followed by the UTF-8 name of the port for identification within the guest (without a NUL terminator).
105 #[doc(alias = "VIRTIO_CONSOLE_PORT_NAME")]
106 PortName = 7,
107}
108
109/// Resize Message Layout
110#[doc(alias = "virtio_console_resize")]
111#[cfg_attr(
112 feature = "zerocopy",
113 derive(
114 zerocopy_derive::KnownLayout,
115 zerocopy_derive::Immutable,
116 zerocopy_derive::FromBytes,
117 zerocopy_derive::IntoBytes,
118 )
119)]
120#[derive(Clone, Copy, Debug)]
121#[repr(C)]
122pub struct Resize {
123 pub cols: le16,
124 pub rows: le16,
125}