chipset_resources/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resource definitions for core chipset devices.
5
6#![forbid(unsafe_code)]
7
8pub mod i8042 {
9    //! Resource definitions for the i8042 PS2 keyboard/mouse controller.
10
11    use mesh::MeshPayload;
12    use vm_resource::Resource;
13    use vm_resource::ResourceId;
14    use vm_resource::kind::ChipsetDeviceHandleKind;
15    use vm_resource::kind::KeyboardInputHandleKind;
16
17    /// A handle to an i8042 PS2 keyboard/mouse controller controller.
18    #[derive(MeshPayload)]
19    pub struct I8042DeviceHandle {
20        /// The keyboard input.
21        pub keyboard_input: Resource<KeyboardInputHandleKind>,
22    }
23
24    impl ResourceId<ChipsetDeviceHandleKind> for I8042DeviceHandle {
25        const ID: &'static str = "i8042";
26    }
27}
28
29pub mod battery {
30    //! Resource definitions for the battery device
31
32    #[cfg(feature = "arbitrary")]
33    use arbitrary::Arbitrary;
34    use inspect::Inspect;
35    use mesh::MeshPayload;
36    use vm_resource::ResourceId;
37    use vm_resource::kind::ChipsetDeviceHandleKind;
38    /// A handle to a battery device for x64
39    #[derive(MeshPayload)]
40    pub struct BatteryDeviceHandleX64 {
41        /// Channel to receive updated state
42        pub battery_status_recv: mesh::Receiver<HostBatteryUpdate>,
43    }
44
45    impl ResourceId<ChipsetDeviceHandleKind> for BatteryDeviceHandleX64 {
46        const ID: &'static str = "batteryX64";
47    }
48
49    /// A handle to a battery device for aarch64
50    #[derive(MeshPayload)]
51    pub struct BatteryDeviceHandleAArch64 {
52        /// Channel to receive updated state
53        pub battery_status_recv: mesh::Receiver<HostBatteryUpdate>,
54    }
55
56    impl ResourceId<ChipsetDeviceHandleKind> for BatteryDeviceHandleAArch64 {
57        const ID: &'static str = "batteryAArch64";
58    }
59
60    /// Updated battery state from the host
61    #[derive(Debug, Clone, Copy, Inspect, PartialEq, Eq, MeshPayload, Default)]
62    #[cfg_attr(feature = "arbitrary", derive(Arbitrary))]
63    pub struct HostBatteryUpdate {
64        /// Is the battery present?
65        pub battery_present: bool,
66        /// Is the battery charging?
67        pub charging: bool,
68        /// Is the battery discharging?
69        pub discharging: bool,
70        /// Provides the current rate of drain in milliwatts from the battery.
71        pub rate: u32,
72        /// Provides the remaining battery capacity in milliwatt-hours.
73        pub remaining_capacity: u32,
74        /// Provides the max capacity of the battery in `milliwatt-hours`
75        pub max_capacity: u32,
76        /// Is ac online?
77        pub ac_online: bool,
78    }
79
80    impl HostBatteryUpdate {
81        /// Returns a default `HostBatteryUpdate` with the battery present and charging.
82        pub fn default_present() -> Self {
83            Self {
84                battery_present: true,
85                charging: true,
86                discharging: false,
87                rate: 1,
88                remaining_capacity: 950,
89                max_capacity: 1000,
90                ac_online: true,
91            }
92        }
93    }
94}