Alioth Code Coverage

reg.rs0.00%

1// Copyright 2024 Google LLC
2//
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 at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// 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 and
13// limitations under the License.
14
15use crate::firmware::acpi::bindings::FadtSleepControlReg;
16use crate::mem::Result;
17use crate::mem::emulated::{Action, Mmio};
18
19pub const FADT_RESET_VAL: u8 = b'r';
20
21#[derive(Debug)]
22pub struct FadtReset;
23
24impl Mmio for FadtReset {
25 fn size(&self) -> u64 {
26 1
27 }
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)]
43pub struct FadtSleepControl;
44
45impl Mmio for FadtSleepControl {
46 fn size(&self) -> u64 {
47 1
48 }
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