reg.rs0.00%
1
// Copyright 2024 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
use crate::firmware::acpi::bindings::FadtSleepControlReg;16
use crate::mem::Result;17
use crate::mem::emulated::{Action, Mmio};18
19
pub const FADT_RESET_VAL: u8 = b'r';20
21
#[derive(Debug)]22
pub struct FadtReset;23
24
impl Mmio for FadtReset {25
fn size(&self) -> u64 {26
127
}28
29
fn read(&self, _offset: u64, _size: u8) -> Result<u64> {30
Ok(0)31
}32
33
fn write(&self, _offset: u64, _size: u8, val: u64) -> Result<Action> {34
if val as u8 == FADT_RESET_VAL {35
Ok(Action::Reset)36
} else {37
Ok(Action::None)38
}39
}40
}41
42
#[derive(Debug)]43
pub struct FadtSleepControl;44
45
impl Mmio for FadtSleepControl {46
fn size(&self) -> u64 {47
148
}49
50
fn read(&self, _offset: u64, _size: u8) -> Result<u64> {51
Ok(0)52
}53
54
fn write(&self, _offset: u64, _size: u8, val: u64) -> Result<Action> {55
let val = FadtSleepControlReg(val as u8);56
if val.slp_en() && val.sle_typx() == 5 {57
Ok(Action::Shutdown)58
} else {59
Ok(Action::None)60
}61
}62
}63