-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Particularly, the InterfaceReady event is useful for knowing when the FPMCU was turned on.
- Loading branch information
1 parent
a2d5504
commit a8121a0
Showing
4 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
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,94 @@ | ||
use std::fmt::Debug; | ||
|
||
use bytemuck::{Pod, Zeroable}; | ||
use num::FromPrimitive; | ||
use num_derive::FromPrimitive; | ||
use strum_macros::IntoStaticStr; | ||
|
||
/// Host event codes. ACPI query EC command uses code 0 to mean "no event | ||
/// pending". We explicitly specify each value in the enum listing so they won't | ||
/// change if we delete/insert an item or rearrange the list (it needs to be | ||
/// stable across platforms, not just within a single compiled instance). | ||
#[repr(u32)] | ||
#[derive(FromPrimitive, IntoStaticStr, Debug)] | ||
pub enum HostEventCode { | ||
None = 0, | ||
LidClosed = 1 << 0, | ||
LidOpen = 1 << 1, | ||
PowerButton = 1 << 2, | ||
AcConnected = 1 << 3, | ||
AcDisconnected = 1 << 4, | ||
BatteryLow = 1 << 5, | ||
BatteryCritical = 1 << 6, | ||
Battery = 1 << 7, | ||
ThermalThreshold = 1 << 8, | ||
/// Event generated by a device attached to the EC | ||
Device = 1 << 9, | ||
Thermal = 1 << 10, | ||
/// GPU related event. Formerly named EC_HOST_EVENT_USB_CHARGER. | ||
Gpu = 1 << 11, | ||
KeyPressed = 1 << 12, | ||
/// EC has finished initializing the host interface. The host can check | ||
/// for this event following sending a EC_CMD_REBOOT_EC command to | ||
/// determine when the EC is ready to accept subsequent commands. | ||
InterfaceReady = 1 << 13, | ||
/// Keyboard recovery combo has been pressed | ||
KeyboardRecovery = 1 << 14, | ||
/// Shutdown due to thermal overload | ||
ThermalShutdown = 1 << 15, | ||
/// Shutdown due to battery level too low | ||
BatteryShutdown = 1 << 16, | ||
/// Suggest that the AP throttle itself | ||
ThrottleStart = 1 << 17, | ||
/// Suggest that the AP resume normal speed | ||
ThrottleStop = 1 << 18, | ||
/// Hang detect logic detected a hang and host event timeout expired | ||
HangDetect = 1 << 19, | ||
/// Hang detect logic detected a hang and warm rebooted the AP | ||
HangReboot = 1 << 20, | ||
/// PD MCU triggering host event | ||
PdMcu = 1 << 21, | ||
/// Battery Status flags have changed | ||
BatteryStatus = 1 << 22, | ||
/// EC encountered a panic, triggering a reset | ||
Panic = 1 << 23, | ||
/// Keyboard fastboot combo has been pressed | ||
KeyboardFastboot = 1 << 24, | ||
/// EC RTC event occurred | ||
Rtc = 1 << 25, | ||
/// Emulate MKBP event | ||
Mkbp = 1 << 26, | ||
/// EC desires to change state of host-controlled USB mux | ||
UsbMux = 1 << 27, | ||
/// The device has changed "modes". This can be one of the following: | ||
/// - TABLET/LAPTOP mode | ||
/// - detachable base attach/detach event | ||
ModeChange = 1 << 28, | ||
/// Keyboard recovery combo with hardware reinitialization | ||
KeyboardRecoveryHwReinit = 1 << 29, | ||
/// WoV | ||
Wov = 1 << 30, | ||
/// The high bit of the event mask is not used as a host event code. If | ||
/// it reads back as set, then the entire event mask should be considered | ||
/// invalid by the host. This can happen when reading the raw event status | ||
/// via EC_MEMMAP_HOST_EVENTS but the LPC interface is not initialized on | ||
/// the EC, or improperly configured on the host. | ||
Invalid = 1 << 31, | ||
} | ||
|
||
#[derive(Pod, Zeroable, Clone, Copy)] | ||
#[repr(C)] | ||
pub struct EcMkbpEventHostEvent { | ||
host_event: u32, | ||
} | ||
impl EcMkbpEventHostEvent { | ||
/// Try getting the host event code enum. If it for some reason is something else, that's an error. | ||
pub fn rust(self) -> Result<HostEventCode, u32> { | ||
HostEventCode::from_u32(self.host_event).ok_or(self.host_event) | ||
} | ||
} | ||
impl Debug for EcMkbpEventHostEvent { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
self.rust().fmt(f) | ||
} | ||
} |
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