Skip to content

Commit 056ec31

Browse files
committed
mec init: Fail if ioperm didn't succeed
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 184f89b commit 056ec31

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

framework_lib/src/chromium_ec/portio_mec.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,20 @@ const _MEC_LPC_DATA_REGISTER1: u16 = 0x0805;
2222
const MEC_LPC_DATA_REGISTER2: u16 = 0x0806;
2323
const _MEC_LPC_DATA_REGISTER3: u16 = 0x0807;
2424

25-
pub fn init() {
25+
pub fn init() -> bool {
2626
#[cfg(target_os = "linux")]
2727
unsafe {
28-
ioperm(EC_LPC_ADDR_HOST_DATA as u64, 8, 1);
29-
ioperm(MEC_LPC_ADDRESS_REGISTER0 as u64, 10, 1);
28+
println!("Init MEC");
29+
let res = ioperm(EC_LPC_ADDR_HOST_DATA as u64, 8, 1);
30+
if res != 0 {
31+
error!("ioperm failed. portio driver is likely block by Linux kernel lockdown mode");
32+
return false;
33+
}
34+
let res = ioperm(MEC_LPC_ADDRESS_REGISTER0 as u64, 10, 1);
35+
assert_eq!(res, 0);
3036
}
37+
38+
true
3139
}
3240

3341
// TODO: Create a wrapper

0 commit comments

Comments
 (0)